I want to display a different content in sidebar for every category, but as I create new categories I have to create the area for it. How can I have the widget areas dynamically?
Leave a Reply
You must be logged in to post a comment.
I want to display a different content in sidebar for every category, but as I create new categories I have to create the area for it. How can I have the widget areas dynamically?
You must be logged in to post a comment.
Not a good thing if you have a lot of categories, so be careful!
First, add the following function in
functions.php
:This is enough, now in Widgets you have a widget area for every category. Now you have to show the area for the category. I like to display the area for categories listings (categories posts listings) and the same area for posts using the category as well (single posts pages).
In
sidebar.php
, add:That’s all, I bet someone can came up with a better code, by now this does the trick.