In this post let's talk about how to set different categories using different categories list style, the article under Different categories use different articles style in WordPress.
First we should to know two function of WordPress is_category
and in_category
, please refer to official documents. In short, these two functions main difference is categories page determine categories should use is_category
, content page determine categories should use in_category
.
WordPress category list in different categories using different style
- Create a independent ID or alias style file
WordPress category determine ID call style file of theme, if can't find that, will use archive.php
, and if archive.php
doesn't exist, will use index.php
.
If your category's ID is 2 and alias is demo, create category-2.php
or category-demo.php
for this category.
- Determine ID to call different style file
Make category ID as 2 use thumb_list.php
style, other use title_list.php
style:
<php if (is_category(2)) { include(TEMPLATEPATH . '/thumb_list.php'); } else { include(TEMPLATEPATH . '/title_list.php'); }
Make category ID as 2, 3, 4 use thumb_list.php
style, other use title_list.php
style:
<php if (is_category(array(2,3,4))) { include(TEMPLATEPATH . '/thumb_list.php'); } else { include(TEMPLATEPATH . '/title_list.php'); }
Make category ID as 2, 3, 4 use thumb_list.php
style, category ID as 5, 6, 7 use img_list.php
, other use title_list.php
style:
<php if (is_category(array(2,3,4))) { include(TEMPLATEPATH . '/thumb_list.php'); } elseif (is_category(array(5,6,7))){ include(TEMPLATEPATH . '/img_list.php'); } else { include(TEMPLATEPATH . '/title_list.php'); }
WordPress artices in different categories using different style
Make post in category ID as 2, 3, 4 use single1.php
style, post in category ID as 5, 6, 7 use single2.php
, other use single3.php
style:
<php if ( in_category(array(2,3,4)) ) { include(TEMPLATEPATH . '/single1.php'); } elseif ( in_category(array(5,6,7))){ include(TEMPLATEPATH . '/single2.php'); } else { include(TEMPLATEPATH . '/single3.php'); }