WordPress — How To Style The Posts On The Basis Of Category

Customizing WordPress and styling your weblog is the play of your imaginations. WordPress opens up the plethora of opportunity for making the customizations work out for you. Here is a quick tip for customizing different category in different style.

Copy the code given below to functions.php and create & replace the stylesheets (stylesheet1, stylesheet2, stylesheet3) with your specific css filenames.

function custom_cat_style()
 {
 ?>
 <link rel="stylesheet" href="<?php bloginfo('template_url')?>/stylesheet1.css" type="text/css" media="screen,projection" />

 <?php
 if( in_category('1') )
 {
 ?>
 <link rel="stylesheet" href="<?php bloginfo('template_url')?>/stylesheet1.css" type="text/css" media="screen" />    

 <?php
 }
 elseif ( in_category ('2') )
 {
 ?>
 <link rel="stylesheet" href="<?php bloginfo('template_url')?>/stylesheet2.css" type="text/css" media="screen" />

 <?php
 }
 elseif ( in_category ('33') )
 {
 ?>
 <link rel="stylesheet" href="<?php bloginfo('template_url')?>/stylesheet3.css" type="text/css" media="screen" />
 <?php }    else {     ?>

 <?php
 }
 }

add_action('wp_head','custom_cat_style');
Divi WordPress Theme