danielsun
Member
Posted 3 years ago #
Hi. This might (and SHOULD) be a no-brainer, but I just can't figure it out:
I have category Bears and Whales and templates for each: category-1.php and category-2.php, which display list of posts from each category.
Now I want to display a single post "Teddy Bear" with different styling (template) than the post "Willy the Whale" which are both in different categories.
How do I do that?
danielsun
Member
Posted 3 years ago #
come on guys it only a simple one!
please?
If I understand correctly, you want the single post from category 1 to be different from the single post in category 2.
To do that, you could use the following in your single.php file (I think... I haven't tested this).
<?php if (in_category( "1" ) {
do this.....
}else if(in_category("2") {
do that....
}?>
Obviously, you would replace the do this, do that with the proper php/html code that you want to use for each category post.
danielsun
Member
Posted 3 years ago #
Yes, I want exactly that, i want separate templates for two separate types of post (two categories).
I know i can do this in php, im a programmer, but, heck, is there no way doing it "properly" ?? Don't tell me WP can't do that!
danielsun
Member
Posted 3 years ago #
Thanks crondeau, the single.php actually works. But again, if this is the only solution it IS ugly.
emanoelmelo
Member
Posted 3 years ago #
try this on the functions.php:
add_filter('single_template', create_function('$t', 'foreach( (array) get_the_category() as $cat ) { if ( file_exists(TEMPLATEPATH . "/single-{$cat->term_id}.php") ) return TEMPLATEPATH . "/single-{$cat->term_id}.php"; } return $t;' ));
Code grabbed from somewhere this forum.