• Resolved lightfoot33

    (@lightfoot33)


    I want to have a different single post template for two of my categories, and despite trying different plugins and code solutions, I am still not getting it to work. The solution I would like to use is one similar to the following (which I found in multiple places as the a working solution) but it’s not working for me. It always shows what ever template is denoted after the “else” line and seems to completely ignore the first two. Here is the full code I have in my single.php file

    <?php
      $post = $wp_query->post;
    
      if (in_category('3')) {
          include(TEMPLATEPATH.'/single-projects.php');
      } elseif (in_category('5')) {
          include(TEMPLATEPATH.'/single-inspiration.php');
      } else {
          include(TEMPLATEPATH.'/single_default.php');
      }
    ?>

    I’m hoping someone can help. I feel like it shouldn’t be this difficult, but I am stumped.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter lightfoot33

    (@lightfoot33)

    Thanks, but I assume that would mean I need to create custom post types, which would change the navigation in the dashboard? I think this would be problematic since there are already hundreds of posts on the site and I was hoping to use code (like I tried above) to make it much more automatic and apply to previous posts.

    Thread Starter lightfoot33

    (@lightfoot33)

    I figured out the solution. I have categories and sub-categories. I thought using the parent category ID# would automatically include all the children categories as well, but it appears that I have to actually list out all the children categories as well.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Single Post Template based on Category’ is closed to new replies.