Community Forums › Forums › Archived Forums › Design Tips and Tricks › Genesis Custom Post Type and single-posttype.php?
Tagged: archive, Custom Post Type, genesis, single
- This topic has 2 replies, 2 voices, and was last updated 9 years, 8 months ago by nuggetweb.
-
AuthorPosts
-
August 21, 2014 at 10:21 am #120249nuggetwebMember
Hi guys,
I have a client who came to me with a website that someone else built using a Genesis child theme. He needs a custom post type for area attractions (called 'attraction') and that is working fine.
Where I'm running into problems is that single-attraction.php doesn't seem to recognize when you're trying to look at a single Attraction. It displays the blog roll just like the archive page should do. I know this link won't work for you, but you can see that I'm looking at a single record:
http://localhost/attraction/nuggetweb-com/
If I do a check for is_single() in single-attraction.php it returns false. This isn't the prettiest code, but here's my single-attraction.php file:
<?php /* Template Name: Attractions Template */ remove_action('genesis_loop', 'genesis_do_loop'); /** * Function that replaces the default loop * with a custom loop querying 'PostType' CPT. */ add_action('genesis_loop', 'gt_custom_loop'); // Remove post meta remove_action( 'genesis_before_post_content', 'genesis_post_info' ); // Output for custom post type 'attraction' add_action('genesis_post_content', 'hcedc_attraction_filter'); function gt_custom_loop() { global $paged; $args = array('post_type' => 'attraction'); // Accepts WP_Query args // (http://codex.wordpress.org/Class_Reference/WP_Query) genesis_custom_loop( $args ); } function hcedc_attraction_filter() { $addr1 = genesis_get_custom_field('hcedc_addr_text'); $addr2 = genesis_get_custom_field('hcedc_addr2_text'); $city = genesis_get_custom_field('hcedc_city_text'); $zip = genesis_get_custom_field('hcedc_zip_text'); $phone = genesis_get_custom_field('hcedc_phone_text'); $post_meta = '<p class="hcedc">' . $addr1 . '<br />'; $post_meta .= ($addr2 != '') ? $addr2 . '<br />' . "\n" : ""; $post_meta .= $city . ', IL ' . $zip . '</p>'; $post_meta .= '<p>' . $phone . '</p>'; $map_addr = $addr1 . "," . $city . ",IL," . $zip; $map = hcedc_google_map($map_addr); $single = (is_single()) ? "<p>I AM SINGLE!</p>":""; $table = $single . ' <table border="1" width="90%"> <tr> <td width="30%" style="vertical-align: top;">' . $post_meta . '</td> <td style="vertical-align: top;">' . $map . '</td> </tr> </table> '; echo $table; } genesis(); // <- everything important: make sure to include this. ?>
I feel like this is one of those things where I'm just missing one key detail, but I'm stuck, so any help is appreciated!
August 21, 2014 at 11:25 am #120256SummerMemberTypically, you don't check for is_single in the single.php template, because the only way it will be called is if it's a single post in the taxonomy you've defined.
That said, your problem is you have a loop. With a single template, all you want to do is style your single post, not generate another loop of posts to display.
Remove the action call to the loop, and remove the conditional check for is_single, and you should see something closer to what you want.
WordPress / Genesis Site Design & Troubleshooting: A Touch of Summer | @SummerWebDesign
Slice of SciFi | Writers, After DarkAugust 21, 2014 at 11:38 am #120261nuggetwebMemberThank you Summer. That's what I needed!
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.