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!
UPDATE
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'); ?>
</div>
<?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>
</a>
</li>
<?php endwhile; ?>
</ul>
</div>
<?php endif; ?>
Register a new sidebar by pasting this into your theme’s
functions.php
file:Create a file called
sidebar-patientedu.php
and paste the following into it:Then paste this whereever you want your sidebar to show up:
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 yourfunctions.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 calledsidebar-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 ownsidebar.php
I hope this helps, and that I didn’t completely miss the mark on your question.