Hey all i am wondering what i need to add in order to have a different sidebar for a set page?

I created a category for the page (called PatientEdu):


And made sure the page was linked to the category:


But it still seems to be using the other category sidebar (Which i also do not know where its at)?


So any help would be great!


My current sidebar.php code is this:

<?php if (is_active_sidebar('default-sidebar')) : ?>
<div id="sidebar">
    <h2>Default Sidebar</h2>
    <?php dynamic_sidebar('default-sidebar'); ?>    
<?php endif; ?>

and the function code:


update 2

Looks like its using the single.php page to populate the sidebar?

<?php if (have_posts()) : ?>                        
    <div id="sidebar">
       <h3><?php echo get_cat_name(CAT_DOCTORS); ?></h3>
           <ul class="info-list">
             <?php while (have_posts()) : the_post(); ?>
              <li <?php if ($post_id == get_the_ID()) {echo 'class="active"';} ?>>
               <a href="<?php the_permalink(); ?>">
                 <span><?php the_title(); ?></span>
            <?php endwhile; ?>
<?php endif; ?>

2 Answers 2


Register a new sidebar by pasting this into your theme's functions.php file:

register_sidebars( 'id' => 'patientedu' );

Create a file called sidebar-patientedu.php and paste the following into it:

<?php if (is_active_sidebar('patientedu')) : ?>
<div id="sidebar">
    <h2>PatientEdu Sidebar</h2>
    <?php dynamic_sidebar('patientedu'); ?>    
<?php endif; ?>

Then paste this whereever you want your sidebar to show up:

<?php get_sidebar('patientedu'); ?>

First, WordPress automatically creates a sidebar for your template if one is not defined (by creating a sidebar.php in your theme).

Secondly, you can register multiple sidebars by using register_sidebars in your functions.php file.

The template function, get_sidebar, accepts a parameter, $name, which determines which sidebar file to get. For example, if you have a file in your theme folder called sidebar-doctors.php, you can call <?php get_sidebar('doctors'); ?> in your theme and get the doctors sidebar.

You can use these techniques together to build a different sidebar for different template pages.

Or! You can go one step further and add the following code and make a sidebar-<cat_slug>.php for each category. If there isn't a php file with that name, WordPress will default to its own sidebar.php

if (is_category( ))
    $cat = get_query_var('cat');
    $yourcat = get_category ($cat);

I hope this helps, and that I didn't completely miss the mark on your question.

  • You're off to a good start with your functions.php file and with your sidebar.php. Where you're checking if (is_active_sidebar('default-sidebar')) of course change "default-sidebar" to whatever you need to like "logos-sidebar". About your single.php, I would comment out the code inside div#sidebar and put in the snippet I wrote in my answer.
    – Alex Lane
    Nov 27, 2012 at 14:33

Your Answer

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

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