• Resolved armstrong1118

    (@armstrong1118)


    I am looking for a way to have ‘templates’ for my single.php based on the category. I went here:

    Link

    and got this code:

    <?php
      $post = $wp_query- >post;
    
      if ( in_category('1') ) {
      include(TEMPLATEPATH . '/single1.php');
    
      } elseif ( in_category('2') ) {
      include(TEMPLATEPATH . '/single2.php');
    
      } else {
      include(TEMPLATEPATH . '/single_other.php');
    
      }
    ?>

    Now, it says to put the code into single.php and create the new single1.php and single2.php. I tried replacing all of the code in single.php with the code above (i guess thats what I am supposed to do with it?) and then I try and view a single post nothing works…I get a blank white screen.

    Does anyone know how I am supposed to implement this so that it will work?

Viewing 4 replies - 1 through 4 (of 4 total)
  • If you have copied all of this in to single.php, you should only get a blank screen if you haven’t put anything in single1.php (presuming the post is in cat 1) or haven’t even created the file.

    Have you created and put something in single1.php?

    Thread Starter armstrong1118

    (@armstrong1118)

    Yea, I changed the in_category to reflect where the post was and I did create the single1.php. It has all the same code as the archive for the category, so I know it works….I dont know if I was supposed to replace everything in single.php with the code above but the site wasnt really specific

    It has all the same code as the archive for the category, so I know it works

    Wrong, I guess. You should work from the original single.php of your theme.

    Also, you may want to take a look at this plugin:
    https://guff.szub.net/2005/07/21/post-templates-by-category/

    Thread Starter armstrong1118

    (@armstrong1118)

    Thanks, I never did get the other thing to work but that plugin works great!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘code for single post templates’ is closed to new replies.