0

I have a site that uses multiple query taxonomy archives.

i.e www.sitename.com/taxonomy1/taxonomy2/taxonomy3

Is there a plugin or method to create a dedicated sidebar for each queried taxonomy archive?

Essentially, there will be 1000 or so archives and i would like to be able to create a unique sidebar for each. Is this possible?

Thanks in advance

Paul

2 Answers 2

1

I've had luck dynamically creating sidebars using a foreach loop. You'd do something like this (untested) in your functions.php file:

$my_terms = get_terms( 'my_taxonomy_name' );
if( ! is_wp_error( $my_terms ) ) {
    foreach( $my_terms as $term ) {
        register_sidebar(
            'name' => $term->name . ' Archive Sidebar',
            'id' => 'archive_sidebar_' . $term->term_id
        );
    }
}

Then, in your taxonomy-my_taxonomy_name.php template file, you'd use something like this (untested) to get your sidebar (some code borrowed from this answer):

<?php
$term_slug = get_query_var( 'term' );
$taxonomy_name = get_query_var( 'taxonomy' );
$current_term = get_term_by( 'slug', $term_slug, $taxonomy_name );
dynamic_sidebar( 'archive_sidebar_' . $current_term->term_id );
?>

Now, having said all that, I question whether this is a good idea. Assuming that generating 1000 sidebars doesn't have a negative performance affect on WordPress (which is a BIG assumption), the UI for the backend user would be terrible. I can't imagine finding the sidebar I actually wanted to use.

While it would be confusing still, I'd encourage you to use Widget Logic or, if you have non-code-savvy users, Widget Logic Visual.

Alternately, drop the whole idea of widgets sidebars and accomplish whatever you need by just using get_query_var() to figure out which term archive you're on in the template and then execute some context-aware code in the template file.

2
  • Thanks for the response, I will actually take you last bit of advice and use a query to generate the content in one sidebar. This will generate the required results based on the archive. It wil be much easier to handle than all those sidebars : )
    – PaulB
    Commented May 8, 2012 at 12:07
  • @PaulB Sounds like a good idea! You had me worried there. If this answered your question, make sure to accept it as the right answer.
    – mrwweb
    Commented May 8, 2012 at 13:49
0

try this -

http://www.wordpressguide.in/want-different-sidebar-for-different-category.html

its easy and simple !

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.