More than 1000+ satisfied clients and counting, since 2010


How to customize sub-categories in WordPress?

A Pen is mightier than a sword- said almost very literary person of the 19th century but, the warriors might beg to differ. Of course, they are bound to but, the main reason behind this quote, as far as I perceive it, is that both these elements are tools to convince others. A sword is a tool of fear that convinces the other person of the primary’s superiority in terms of force where as the pen uses the tool of reason, logic and sense through which it yearns to take in the other person in to it’s stride. If that fails, then comes the need of sword but that needn’t always fail when we have an alternative of improvising our convincing techniques which can be done by segregating your words into sections of priority and precedence. A haphazardly presented logic is worse than not giving a reason. We need to categorize what we need to say by first dividing what we intend to convey to the listener or for that matter the reader. After that, if we wish to we can sub group our content for better understanding of the receiver. Possibly now a days, the largest platform present for thoughts, ideas and opinions to converge are the ones which are online that are the blogs and forums. We in this article will concentrate on wordpress blogs for more preciseness. WordPress blogs happen to have a salient feature of categories and sub-categories that divide a blog’s content into divisions of users choice. Although, done by the handler or administrator of the blog, the divisions are more to suit the readership of the blog. This actually creates a convenient way of accessing the blog posts for the user wherein he/she will choose a category of his requirement and will read content related to their choice. This promotes a better understanding of the readership for the blogger and also is quite good for the reader as well as he will not be required to scrounge the whole blog for post related to his interests.

So the significance of categorization and sub-categorization is quite evident from the above paragraph, now we move on to how to customize the sub categories of a wordpress blog. A beautiful feature of wordpress is the presence of numerous widgets and plugins for any job to be done. We can create a similar solution but instead of a single widget we can have a fully capable and working widget sidebar for each category and sub category. Read through to know how to customize sub-categories in WordPress. This can be done by adding the following code to your functions.php file:

add_action( ‘widgets_init’, ‘category_sidebars’ );

function category_sidebars() {

$categories = get_categories( array( ‘hide_empty’=> 0 ) );

foreach ( $categories as $category ) {

if ( 0 == $category->parent )

register_sidebar( array(

name’ => $category->cat_name,

‘id’ => $category->category_nicename . ‘-sidebar’,

‘description’ => ‘This is the ‘ . $category->cat_name . ‘ widgetized area’,

‘before_widget’ => ‘<aside id=”%1$s” class=”widget %2$s”>’,

‘after_widget’ => ‘</aside>’,

‘before_title’ => ‘<h3 class=”widget-title”>’,

‘after_title’ => ‘</h3>’, ) );}}

put the following code in the sidebar.php and you are set:

$sidebar_id = ( is_category() ) ? sanitize_title( get_cat_name( get_query_var( ‘cat’ ) ) ) . ‘-sidebar’ : ‘sidebar’;

dynamic_sidebar( $sidebar_id );

Written by

The author didnt add any Information to his profile yet