Community Forums › Forums › Archived Forums › General Discussion › Custom POST type template
Tagged: Explanation
- This topic has 6 replies, 2 voices, and was last updated 10 years, 7 months ago by streetfire.
-
AuthorPosts
-
August 7, 2013 at 8:00 pm #54789streetfireMember
I've been using Genesis for a while. For the most part I love it... except when it comes to custom post type templates. I've done a lot of research and I just can't seem to make anything work. Currently I'm using the Outreach theme.
This is what I need to do:
- Create custom single post (not page) template and reconstruct the layout of the post. For example I want to re-position the featured image, body content, add custom fields, etc.
I am familiar with doing this in standard WordPress templates, but Genesis does not handle it the same.
Can anyone shed some light? Thanks.
August 9, 2013 at 1:40 pm #55308MarcyParticipantYou need to manage the custom post type template with the Genesis hooks. You just turn them on or off to get the layout you want for your page. And if sometimes, it's easier for you to do certain things with WordPress code, like custom loops, for instance, that works too. You can find nearly anything you need to know by using Google search with genesis at the beginning.
This tells you how to use hooks:
http://my.studiopress.com/docs/hooks/
This is where the hooks are located:
http://genesistutorials.com/visual-hook-guide/
And Nick has lots of info on hooks (as do others).
http://designsbynickthegeek.comHere is my sample to get you started. Basically all I left was the title, and then I replaced the content area with the custom post type content.
<?php /* This is the template for the single supporter custom post page - single-supporter.php */ remove_action( 'genesis_before_post_content', 'genesis_post_info' ); remove_action( 'genesis_after_post_content', 'genesis_post_meta' ); remove_action( 'genesis_after_post', 'genesis_get_comments_template' ); remove_action( 'genesis_post_content', 'genesis_do_post_content' ); add_action( 'genesis_post_content', 'c3_supporter_post_content' ); function c3_supporter_post_content() { global $post; // Needed or get_post_meta won't return data $logo = get_post_meta($post->ID, '_ccc_logo_id', true);// Note the _id $description = get_post_meta($post->ID, '_ccc_description', true); //This is from Bill Erickson on GitHub for Custom MetaBoxes if ( $logo ) : $logo_thumbnail = wp_get_attachment_image_src( $logo, 'supporter-thumbnail' ); echo '<img />'; endif; echo '<div class="supporter-info">'; if ($description) { echo '<p><span>About:</span></p>'; echo '<p>'. $description .'</p>'; } echo '</div> <!-- end .supporter info -->'; } //End function c3_supporter_before_post_content genesis();
Note: There are underscores in the code that aren't showing in my browser, so you may need to copy the code into an editor to see it better.
Marcy | Amethyst Website Design | Twitter
August 15, 2013 at 11:05 am #56599streetfireMemberHi Marcy, thanks very much for that information and the sample code. I plugged it into my site and am looking at it know. A great kickstart. Thank you.
August 15, 2013 at 12:23 pm #56614MarcyParticipantI'm glad it's helping. I forgot to add that the method I used for creating the custom post type uses get_post_meta to retrieve the custom fields. Some plugins/methods use the_field or get_the_field.
Marcy | Amethyst Website Design | Twitter
August 30, 2013 at 6:43 pm #59802streetfireMemberMarcy, do you by change have any suggestions for doing this same exact thing for a custom post type archive template? I.e. archive-customposttype.php.
The code above doesn't seem to do it.
September 3, 2013 at 12:42 am #60369MarcyParticipantAre you using a plugin to create your custom post type? Or are you creating it yourself in your functions.php?
What do you want in your archive page? Just a list of custom post types?
Marcy | Amethyst Website Design | Twitter
September 3, 2013 at 6:38 pm #60537streetfireMemberMarcy,
Yes I am using a plug in called CustomPress from WPMUdev.org. Basically yes, I'd like to pull a list of the custom post types and have the featured image, excerpt, and a read more link. My goal is mainly to re-arrange the layout of those items. -
AuthorPosts
- The forum ‘General Discussion’ is closed to new topics and replies.