• You’ve all been pretty helpful so far in my questions, so thanks in advance. ๐Ÿ™‚

    Anyway, I’m developing a fairly complicated WordPress website. It has an articles section and a blog section. I need the articles and the blogposts to utilize different forms of single.php. What I mean is, one needs to use a single.php with one layout, and the other use something like a single2.php with a different layout.

    I just can’t find the code snippet to do something like this. Thanks!

Viewing 5 replies - 1 through 5 (of 5 total)
  • a little Google research:

    from http://www.webmaster-source.com/2007/11/13/wordpress-as-an-online-magazine/

    How about having different single.php templates for posts in different categories? Just rename your normal single.php template to normal-single.php and create as many alternate single templates as you need. Next, create a new single.php and do something like this:

    <?php
    $post = $wp_query->post;
    if (in_category(‘3’)) {
    include(TEMPLATEPATH . ‘/featuredpost-single.php’);
    } else {
    include(TEMPLATEPATH . ‘/normal-single.php’);
    ?>

    Using if statements, you can tell WordPress to use different templates depending on the category. If you only need to make a minor tweak for a certain category, you donโ€™t need to go so far as to have a separate template. You can just put

    <?php if (!in_category(‘3’)) { ?>
    Whatever you want to appear on permalink pages that are not in category 3.
    <?php } ?>

    I use in_category() on my single post template. That way I can cut-out some of the extras if a post is in my Sideblog category.

    Thread Starter digitaljohn

    (@digitaljohn)

    Thanks for the solution! I tried Google, but I guess didn’t come up with good search terms.

    So easy when I look at it that way… I just need to start thinking like a PHP coder. Thanks again! ๐Ÿ™‚

    <?php if (!in_category(‘3’)) { ?>
    Whatever you want to appear on permalink pages that are not in category 3.
    <?php } ?>

    What if I would like only category 3 to display?

    problem solved:

    <?php if ( in_category(11) ) {
    echo ‘ยซ Return to Testimonials
    ‘;
    } else {
    echo ”;
    }
    ?>

    problem solved:

    <?php if ( in_category(11) ) {
    						echo '<a href="http://protectyourcircle.com/testimonials/" title="Return to Testimonials">ยซ Return to Testimonials</a> <br />';
    					} else {
    						echo '';
    					}
    					?>
Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Using multiple single.php’ is closed to new replies.