Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

(Moderator's note: The original title was "How can I create create and use a custom template for custom post types in the Genesis theme framework?")

I'm using the Genesis theme framework, with an almost completely 'stock' child theme. I have the WP Easy Post Types plugin installed, and have created one custom post type ("Members"). I have two custom fields created to use for the 'member' post type (phone number and address). I'm trying to figure out how to display the information from those fields in two places: example.com/members and example.com/members/bob. Genesis doesn't support the typical single-posttype.php file to create a template for the custom post type, but even if it did, that doesn't take care of example.com/members. Any suggestions on how to get the desired information to display?

share|improve this question
    
It turns out I was wrong about Genesis not supporting that method. See my answer below. –  tnorthcutt Aug 21 '10 at 4:07

4 Answers 4

Take a look at how Matt Wiebe does it in his "Smarter Custom Post Types" plugin:

http://somadesign.ca/projects/smarter-custom-post-types/

The relevant function is here:

function my_custom_template_include( $template ) {
    if ( get_query_var('post_type') == 'members' ) {

        if ( is_single() ) {
            if ( $single = locate_template( array( 'members/single.php') ) )
                return $single;
        }
        else { // loop
            return locate_template( array(
                'members/index.php',
                'members.php', 
                'index.php' 
            ));
        }

    }
    return $template;
}

add_filter( 'template_include', 'my_custom_template_include' );
share|improve this answer
    
It seems like that still requires the use of a separate .php file for /members and /members/bob, but doesn't Genesis require everything to be in the child theme's functions.php file? –  tnorthcutt Aug 17 '10 at 19:57
    
Honestly, I don't know. If you need support for a premium theme, I suggest you go to Genesis' support forums. That's what you're paying for in the Theme. I have never used Genesis, so I can't answer for sure. I can tell you how it's done in a normal WordPress install, though, which is what I've done. I can't imagine Genesis is so restrictive that you can't customize the child themes. –  John P Bloch Aug 17 '10 at 20:07
    
Nice bit of code! –  MikeSchinkel Aug 17 '10 at 20:10

Could someone clarify the next step of this process? I have a similar custom post type in a Genesis child theme and need to change the loop on multi-post taxonomy pages as well as single custom post pages. Where does the custom code for the loop go in this case? Thanks!

share|improve this answer

This template needs to go into the child theme folder, though, not Genesis.

Edit:

You will need to manually create the single-$posttype.php and add it to the child theme as noted above. Please take a look at WordPress Template Hierarchy. It goes without saying anything you add to a child theme will override the parent theme files.

share|improve this answer
    
Excellent point, and added to my answer. For future reference, if you're commenting on an answer (or the original question), please use a comment, rather than writing an answer. –  tnorthcutt Aug 22 '10 at 20:20
up vote 0 down vote accepted

Turns out I was wrong, Genesis does support using the page_posttype.php method of creating a custom template. It turned out to be very simple. Here's the contents of my page_members.php file (located in the child theme folder):

<?php
/*
Template Name: Members
*/

remove_action('genesis_loop', 'genesis_do_loop');
add_action('genesis_loop', 'custom_loop');
function custom_loop() {

    global $paged;
    $args = array('post_type' => 'members');

    genesis_custom_loop( $args );

}

genesis();
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.