Dynamic Sidebar
Having a dynamic sidebar is a great way to make your website more user-friendly! It lets you display extra content to enhance your pages, basically each page has a it’s own sidebar. If you go through this theme and click on different pages, you will notice that the sidebar changes. That is because of dynamic sidebar.
The first thing you need to make sure you have a single.php file in your WordPress theme. Single.php is what people will see once the click the comments link in your blog. If you don’t have that file, create one and paste the following code into it.
<?php get_header(); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<h1><?php the_title(); ?></h1>
<!-- by <?php the_author() ?> -->
<?php the_content('Read the rest of this entry »'); ?>
<?php wp_link_pages(array('before' => '<p><strong>Pages:</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); ?>
<p class="info"> <?php edit_post_link('Edit', ' | ', ''); ?></p>
<?php comments_template(); ?>
<?php endwhile; else : ?>
<h1>Not Found</h1>
<p>Sorry, but you are looking for something that isn't here.</p>
<?php endif; ?>
</div>
<?php get_footer(); ?>
You can also edit the code to fit your layout the way you want it to.
Next thing is to go into your sidebar.php, copy everything in it and paste into a file or something just incase you need it. Clear everything except for <div id="sidebar"> </div>
Paste the code below in between your sidebar divs. This code will show up in your home page and your home page only.
<?php if (is_home()) { ?>
Write what you want here
<?php } ?>
The next code should go under the first one, this one will show up in your comments page. When the comment link your blog is clicked on, this will be the one that shows up.
<?php if (is_single()) { ?>
text goes here
<?php } ?>
The next codes are for your archives and your categories. I already put in the code for categories, but as for your archive, it’s up to you. You also add more codes to the categories.
<?php if (is_category()) { ?>
<?php echo category_description(); ?>
<div class="box">
<h2>Categories</h2>
<?php wp_list_categories( $args ); ?>
</div>
<?php } ?>
<?php if (is_archive()) { ?>
text goes here
<?php } ?>
These las codes are freebies, this is where you can put any page name. It could be about, tutorials, or anything like that. It’s all up to you. This code can be used as much as you like as long as you change the page names.
<?php if1 or (is_page('name')) or (is_page('name')) or (is_page('name')) or (is_page('name')) or (is_page('name')) or (is_page('name'))) { ?>
<?php } ?>
You can add more pages by copying the or (is_page(‘name’)) and pasting it back in as much as you want. Make you put it in the right spot (some where in the middle), make sure to have the ” in the right place and the spaces should also be right.
If you need more, you can use the one below also.
<?php if2 or (is_page('name')) or (is_page('name')) or (is_page('name')) or (is_page('name')) or (is_page('name')) or (is_page('name')) or (is_page('name')) or (is_page('name')) or (is_page('name')) or (is_page('name')) or (is_page('name')) or (is_page('name')) or (is_page('name')) or (is_page('name')) or (is_page('name')) or (is_page('name')) or (is_page('name')) or (is_page('name'))) { ?>
<?php } ?>
If you have more questions, feel free to ask me.