sumitkrdey1
Member
Posted 1 year ago #
I am new to wordpress.
I want to have different look and feel for different categories of post.
I have figured that that category-<>.php can be used for different listing. But I what about the detail ie: the post itself. How can have different look and feel for different posts belonging to a different category.
Regards
Sumit Dey
in your category-<>.php you can define the html structure and the used css ids and classes, to exactly show your post(s) as you want.
more difficult if you then click on the single post; you could try to solve this with a series of if statements in single.php, such as:
<?php if(in_category(1)) { ?>
html/php and css ids/classes to show the post as you want
<?php elseif(in_category(2)) { ?>
html/php and css ids/classes to show the post as you want
<?php elseif(in_category(3)) { ?>
html/php and css ids/classes to show the post as you want
<?php elseif(in_category(4)) { ?>
html/php and css ids/classes to show the post as you want
<?php elseif(in_category(5)) { ?>
html/php and css ids/classes to show the post as you want
<?php } else { ?>
html/php and css ids/classes to show all other post
<?php } ?>
sumitkrdey1
Member
Posted 1 year ago #
Thank you for responding.
This definitely provides a way to resolve the problem. The only challenge that I see in this approach is that the single.php file will grow with the categories.
Is there any cleaner way :) , If possible.
you can grow the number of template files instead:
<?php
if(in_category(1)) { include TEMPLATEPATH . '/single_post_cat_1.php'; }
elseif(in_category(2)) { include TEMPLATEPATH . '/single_post_cat_2.php'; }
elseif(in_category(3)) { include TEMPLATEPATH . '/single_post_cat_3.php'; }
else { ?>
'normal' single code to show post
<?php } ?>
and then make new files single_post_cat_1.php (and so on) in the theme folder, which contain the individual code for each category single post.
you can choose how much of single.php you want to 'externalize'.
sumitkrdey1
Member
Posted 1 year ago #
Cool. Thank you so much ..