Solved

how do I Setup templates for WordPress 3.0 Custom Post Type?

Posted on 2011-02-16
3
275 Views
Last Modified: 2012-05-11
I created a post type called Surgeons and I want to set a spacific template for this page type.
It looks like it is just using single.php as the template. How do I change this to a spacific one of my choosing?

Here is the code I added to the functions.php
add_action( 'init', 'create_my_post_types' );    

function create_my_post_types() {
    register_post_type( 'Surgeons',
        array(
            'labels' => array(
                'name' => __( 'Surgeons' ),
                'singular_name' => __( 'List Surgeons' )
            ),
            'public' => true,
            'hierarchical' => true,
            'show_ui' => true,
            'publicly_queryable' => true,
            'exclude_from_search' => false,
            'menu_position' => 5,
            'supports' => array( 'title', 'editor', 'comments', 'trackbacks', 'author', 'excerpt', 'custom-fields', 'thumbnail' ),
            'rewrite' => array( 'slug' => 'mypage', 'with_front' => false ),
        )
    );
}

Open in new window

0
Comment
Question by:jbrashear72
  • 2
3 Comments
 
LVL 23

Expert Comment

by:jeremyjared74
ID: 34910684
Copy the index.php file and paste it into a text editorl
Add this to the very top:
<?php
/*
Template Name: Surgeons
*/
?>

Open in new window

Then name the file as surgeons.php and add it to your theme folder. You will now have the option to use this page template from the page editor page type drop menu.
0
 
LVL 3

Author Comment

by:jbrashear72
ID: 34910768
But this is a post not a page. the drop down for templates does not show up.

I was told that if I added a file called single-Surgeons.php that this would work but that is being ignored too.
0
 
LVL 23

Accepted Solution

by:
jeremyjared74 earned 500 total points
ID: 34911683
OK for that you need to do this:

Create a custom page template like I suggested earlier, but put this in the top of the page instead:
<?php
/*
Single Post Template: Surgeons
Description: This part is optional, but helpful for describing the Post Template
*/
?>

Open in new window


Then you need to add this to your single.php:
    <?php
    $post = $wp_query->post;
    if ( in_category('10') ) {include(TEMPLATEPATH . '/singleOranges.php');}
    elseif ( in_category('11') ) {include(TEMPLATEPATH . '/singleApples.php');}
    elseif ( in_category('12') ) {include(TEMPLATEPATH . '/singleGrapes.php');}
    else {include(TEMPLATEPATH . '/singleOriginal.php');
    }
    ?>

Open in new window

Then upload your new template page to your theme file. Now your posts will change templates depending on the category it is in.

NOTE: in_category("10") is where you need to add the category that will hold the posts for the template you want to use this in. So you might want to create a category for all posts that you want styled this way, then get the category id and place it where the 10 is. I added a few more template choices (11, 12) in case you wanted more. If you don't, then just give them a number like 9999 or 9998 so they don't get used.
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In order to have all security and back ups taken care of, WordPress users can sign up for services with WP Engine.
Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
The purpose of this video is to demonstrate how to integrate Mailchimp with WordPress, by placing a Mailchimp signup form on a WordPress Page or Post. This will be demonstrated using a Windows 8 PC. Mailchimp will be used. Log into your Mailchiā€¦
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question