- a developer's blog

How to add different sidebars for different categories on WordPress

Lets say you have a word press site where you teach wannabes how to play the guitar. And then lets say you have categorized your website into the follwoing categories :

1.  Acoustic guitar for beginners

2. Learn Bass guitar

3. Learn Electronic Guitar

4. Advanced Guitar Lessons

These 4 categories target 4 different sets of users with 4 different sets of requirements.

If you stick to the traditional word press setup, you have one sidebar for all these 4 category of visitors.

Here’s a simple tweak to show different sidebars for different categories on WordPress:

Step 1. Using a FTP program open wp-content/themes/youractivetheme/

Step 2.  Locate and make as many number of  copies of  sidebar.php as you require. For the above example, i will make say 4 copies(since i have 4 different catrgories)- rename all the 4 sidebars into something indicative. For e.g i might reame my sidebars as: sidebarbeginners.php, sidebarbase.php, sidebarelectronic.php, sidebaradvanced.php.

Step 3. Modify each of these sidebar codes as per your requirement

Step4. Open your single.php to edit and locate the code

include ('sidebar.php');

replace it with a conditional code

if is_category ('slugnameofcategory1'){include ('sidebarbeginners.php')}
If is_category ('slugnameofcategory2'){include ('sidebarbase.php')}

and so on for each separate category.

Save it and that’s it, you are done :)