Custom POST type template

Community Forums Forums General Discussion Custom POST type template

This topic is: not resolved

Tagged: 

This topic contains 6 replies, has 2 voices, and was last updated by  streetfire 1 year, 2 months ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #54789

    streetfire
    Participant
    Post count: 9

    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.

    #55308

    Marcy
    Participant
    Post count: 383

    You 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.com

    Here 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]
    <?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 ‘‘;

    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();

    [/php]

    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.


    • This reply was modified 1 year, 3 months ago by  Marcy.
    • This reply was modified 1 year, 3 months ago by  Marcy.
    #56599

    streetfire
    Participant
    Post count: 9

    Hi 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.

    #56614

    Marcy
    Participant
    Post count: 383

    I’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.


    #59802

    streetfire
    Participant
    Post count: 9

    Marcy, 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.

    #60369

    Marcy
    Participant
    Post count: 383

    Are 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?


    #60537

    streetfire
    Participant
    Post count: 9

    Marcy,
    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.

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.