WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Baffling category-specific sidebar problem (3 posts)

  1. rwwood
    Member
    Posted 4 years ago #

    I have the following in functions.php,:

    register_sidebar(array(
    	'name'=>'sidebar',
        'before_widget' => '<li id="%1$s" class="widget %2$s">',
        'after_widget' => '</li>',
        'before_title' => '<h2 class="widgettitle">',
        'after_title' => '</h2>',
    ));
    register_sidebar(array(
    	'name'=>'category-sidebar',
        'before_widget' => '<li id="%1$s" class="widget %2$s">',
        'after_widget' => '</li>',
        'before_title' => '<h2 class="widgettitle">',
        'after_title' => '</h2>',
    ));

    I have the following in category-sidebar.php,:
    <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('category-sidebar') ) : ?>

    and I have the following in category.php.:`
    <?php get_sidebar('category-sidebar'); ?>`

    Both "sidebar" and "category-sidebar" show up in the admin interface and I can add different widgets to each one. Nevertheless, when category.php is called, the default sidebar (sidebar.php) is loaded, not category-sidebar.php. I've searched the forums and everything I have seems to be correct, but I still get the wrong sidebar for the category template.

    Any help would be appreciated.

  2. alchymyth
    The Sweeper & Moderator
    Posted 4 years ago #

    <?php get_sidebar('category-sidebar'); ?>

    with a code like this, the name of your sidebar file needs to be

    sidebar-category-sidebar.php

    http://codex.wordpress.org/Function_Reference/get_sidebar

  3. rwwood
    Member
    Posted 4 years ago #

    Thanks. I missed that slightly strange coding in the get_sidebar docs. Funny because in the rest of the sidebar related files, you would use just "category-sidebar", ie. in dynamic_sidebar(category-sidebar)

    Thanks again.

Topic Closed

This topic has been closed to new replies.

About this Topic