• Will WP allow me to pass categories through a conditional tag like “is_single()”? I am building a site that is organized by categories and for each nav item, I am using Category titles but want specific page templates to be used for single.php when an article is clicked on.

    OR

    Does WP allow multiple single.php files?

    single-news.php
    single-staff.php
    Both being single post pages from their respective category parents.

    Thanks.

Viewing 3 replies - 1 through 3 (of 3 total)
  • On the template hierarchy you check what kind of templates WordPress will take.

    WordPress will not take single-cat.php. Instead you could use a conditional tag on your single.php to check what category the post is in and then change the stylesheet according to the category.
    Something like you can read here.

    Does WP allow multiple single.php files?

    No – not unless you’re using custom post types.

    Thread Starter danmerk

    (@danmerk)

    Thanks for the help. This is how I remedied it. May be a slight hack, but works perfectly with what I am heading for.

    Single.php

    <?php
    if (in_category('news')) {include (TEMPLATEPATH . '/single-news.php');
    }
    else if (in_category('staff')) {include (TEMPLATEPATH . '/single-staff.php');
    }
    else { include (TEMPLATEPATH . '/single.php');
    
    }
    ?>

    Nothing else on that page. Then it checks for the two files I have on the server. Real clean.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Conditional tags with Single.php’ is closed to new replies.