Placing a specific sidebar on a particular page

Placing specific sidebars where you want will enable you to turn a simple blog into a CMS style site such as gekko longboards where I’ve put a shopping cart widget on some pages (but not all) and a further 4 sidebars in the footer giving me a really flexible content framework.

This assumes you already have widgets enabled and multiple sidebars set up (if you don’t, then report back for a more in depth tutorial in a few weeks). It also assumes you are happy to root around in the basic php files from your blog…

There are several logical ways of setting this up but for me, the easiest is to place a php call for a specific sidebar in your page.php file as follows:

I want to create a sidebar no.2 on a page called dave (ie www.yourblog/dave)

First: create the definitions for sidebar no.2 in a file called sidebar2.php (this will also allow you to specifically style sidebar2 in your CSS later) and place it in your themes directory (ie www.yourblog/wp-content/themes/sidebar2.php).

<div id="sidebar">
   <div id="sidebar2">
     <?php if ( !function_exists('dynamic_sidebar')
      || !dynamic_sidebar(2) ) : ?>
     <?php endif; ?>
   </div>
</div>

then you can place a call for that specific sidebar from your page.php, making sure that it will only show up on the page called ‘dave’

<?php if (is_page('dave')) get_sidebar2(); ?>

Then place the required widgets in sidebar no.2 from your dashboard. If you repeat this process for specific sidebars and pages this will enable you to place dynamic content all over your site.

One Comment

  1. Posted January 5, 2010 at 6:54 pm | Permalink

    This is why I employ you to help me ……. *heads spins*

Post a Comment

Your email is never shared. Required fields are marked *

*
*