WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] code for single post templates (5 posts)

  1. armstrong1118
    Member
    Posted 6 years ago #

    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?

  2. Joe Hoyle
    Human Made
    Posted 6 years ago #

    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?

  3. armstrong1118
    Member
    Posted 6 years ago #

    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

  4. moshu
    Member
    Posted 6 years ago #

    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:
    http://guff.szub.net/2005/07/21/post-templates-by-category/

  5. armstrong1118
    Member
    Posted 6 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.