Cool use for secondary sidebar widget

I’m really liking some of the features in WordPress 3. As someone who writes WordPress templates for clients to use as a CMS, this version has gone a long way to make it even easier.

Because most of my WordPress installs are for commercial sites I tend to set them up with focus on writing pages rather than posts. Posts become great as “Latest News” style pages.

One of the things that makes this even easier is secondary widgets in the sidebar. Essentially this allows us to use the primary widget area to place additional content across the whole site and focuses the secondary widget area to focus on posts.

What this means is you can have your search bar or custom text that appears on every page but target blog specific items, such as calendars, tag clouds and archive links to posts only.

This is done by slightly modifying the secondary widget code in the sidebar.php file

As I want the secondary widget area to only display in posts I’m going to use the is_page conditional tag to do this. You should find the following code around line 45 on the sidebar.php page

<?php
 // A second sidebar for widgets, just because.
 if ( is_active_sidebar( 'secondary-widget-area' ) ) : ?>

Modify the above code so it looks like this

<?php
 // A second sidebar for widgets, just because.
 if ( !is_page() && ( is_active_sidebar( 'secondary-widget-area' ) ) ) : ?>

Secondary widgets will now display ONLY on the posts page – Simple, huh!

This entry was posted in Hints and Tips, Technical and tagged . Bookmark the permalink.

One Response to Cool use for secondary sidebar widget