3

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

1
  • It turns out I was wrong about Genesis not supporting that method. See my answer below. Aug 21, 2010 at 4:07

4 Answers 4

1

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

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' );
3
  • 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? Aug 17, 2010 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. Aug 17, 2010 at 20:07
  • Nice bit of code! Aug 17, 2010 at 20:10
0

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!

0

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.

1
  • 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. Aug 22, 2010 at 20:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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