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.

I need to set a custom template for a custom post type with standard wordpress functionality like this: Creating_Your_Own_Page_Templates

I found these: 1 - custom post template , 2 - single post template , but its not working for a custom post type and this works only for built-in wordpress posts.

share|improve this question
    
You can add custom post type support to the first plugin you listed, it's covered in the other notes section. Very well written plugin to, should address your needs. –  t31os Dec 26 '11 at 12:31
add comment

1 Answer

up vote 0 down vote accepted

I went through the same problem a few months back. After several different ways I finally found a way that worked. Try adding this to your themes functions.php file (be sure to replace both instances of portfolio to match the actual names you use):

<?php
add_action("template_redirect", 'your_cust_pt_redir');
function your_cust_pt_redir() {
   global $wp;
   global $wp_query;
   if ($wp->query_vars["post_type"] == "portfolio") { // Change Portfolio to your Post Type
      if (have_posts())   {
         include(TEMPLATEPATH . '/portfolio.php'); // The Custom Template
         die();
      } else {
         $wp_query->is_404 = true;
      }
   }
}
?>
share|improve this answer
    
thanks for interest , you may point me to the right way , but i think is it better than to use your code or patch that plugins ? that i tell you in above when i want to use this codes several number in a big site that need to best performance –  Behnam Dec 26 '11 at 9:18
add comment

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.