thinkeric
Member
Posted 7 years ago #
Spent the better part of the afternoon trying to figure this out, and I surrender! Here's my quandry:
What I would like to do is have multiple ways to display a single post, depending on what category the post falls into. For example, a blog entry with lots of text would have a different layout than a blog entry with a single photo. Setting up two different categories is not the problem... it's the fact that they appear to use the same single.php file.
I'm just not finding what I'm looking for in any of the documentation, so if someone can point me in the right direction, I would be most appreciative.
http://codex.wordpress.org/Template_Tags/in_category
The page isn't complete at the moment, but that's the tag you'll want.
if (in_category('2')) {
// if the post is in category 2, do one thing
} elseif (in_category('3')) {
// if the post is in category 3 (but not 2), do another thing
} else {
// if the post in neither category 2 nor 3, do something else
}
You could either write out all the code in the one file, or just have a very brief single.php where the only things in those if statements are PHP includes
It's also possible to write a plugin that does all of this for you, but I don't know of one yet.