Here is my goal:
Specifically on a tag/archive page: I would like to show a different sidebar for each category that is displayed on the page.
What I have done now: I have three categories, 'Paintings', 'Photography', and 'Objects'. When a tag page is displayed, I want to check if it has any posts from the category 'Paintings' and if so, I would like it to display the dynamic_sidebar 'paintings-sidebar'.. Photography -> photography_sidebar and Objects -> object_sidebar.
This part I have accomplished.
My issue comes when a tag/archive page contains posts from multiple categories. For example, posts from category 'Paintings' and posts from category'Photography'. In which case I would like to have 'paintings_sidebar' and 'photography_sidebar' show up.
As it is now, only the sidebar for the most recent post's category is displayed in the sidebar.
What am I doing wrong? :(
Here is my little bit of code:
if (is_archive()) {
if (in_category( 'paintings' )) {
dynamic_sidebar( 'paintings-sidebar' );
}
if (in_category( 'photography' )) {
dynamic_sidebar( 'photography-sidebar' );
}
if (in_category( 'objects' )) {
dynamic_sidebar( 'objects-sidebar' );
}