How to Create Smart Dynamic Sidebars

by SBA · 14 comments

There is a solution for those times when you want to display a widget on certain pages but not others. The most typical need is to hide widgets on the home page, but you don't have to stop there. The WP plugin called "Widget Logic" let's you pick and choose your sidebar dynamics.

You can do the same thing using code and WP's conditional tags, documented in Codex. However most of us don't routinely dig into template code. So for us the plugin is perfect. We just need to know the basic conditional tags.

How to educate your widgets in WP

Using Widget Logic, every widget shows a box at the end of the text/html code. You use the box to key in the logic that determines when the widget displays. All based on conditions that match the page, post or category.

Don't let the 'logic' part intimidate you --- the average blogger will need to address a limited number of conditions. Your widget will be smart but not a rocket scientist!  Here are the basics:

The Home Page only is_home()
The Blog Front Page only is_front_page()
A Single Page - any post page is_single()
or Post number 34 is_single('34')
or Post titled "SEO Tips" is_single('SEO Tips')
A Page Page - similar to logic above,just substitute "page" is_page()
A Category Page - again, similar to page or posts above. is_category('Design')

Notes for other situations:

  1. To list multiple pages ids, titles and/or categories, use the array parameter.
    e.g.  is_single array(('34', '45', '7 productivity tips')) show only on those posts.
  2. To exclude pages, posts or categories place an exclamation point before the logic.
    e.g. ! is_category('Design')

Making Smart Blogger Sidebars

widget hide and seek

As with most higher education on Blogger, you need to modify the theme's template.  Here are a couple of articles that explain how to hide widgets on the home, single or archive pages:

How to Hide Blogger Widgets on Home Page
Show or Hide Blogger Widgets (addresses categories)

Here's How We Use Widget Logic

is_single()

These don't show on the home page, menu pages or archive pages: Google Ad; Subscribe box; All about ads and buttons; Recent posts; Top commentators; Recent comments; Facebook; Grab Button.

I'm considering showing some of these only on specific categories, allowing us to move the widget nearer the top of the page.

Tip: How to find the page ID to include or exclude from widget display

Many widgets expect or allow you to specify the numerical page ID. In WordPress, to find the page ID
go to Pages->Edit and hover over the title of the page. The status bar of your browser will display a URL with a numeric ID at the end. That's the page ID!

statusbar-page-id

image by WP widget support

or you can install a plugin called Simply Show IDs which shows the IDs of your posts, pages, and categories directly on the dashboard. This is a screen-shot on the developer's site:

notice # under ID column

How Smart are your Sidebars?

Leave a comment sharing your thoughts on this article and how you manage your sidebars --- or are they managing you?

0saves
If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.
4 Reasons For Subscribing
  • Get Full Posts Delivered Directly To Your Inbox.
  • Get Exclusive Freebies For Subscribers.
  • No "Buy This, Buy That" Mails!
  • 100% Privacy. Your EMail Address Will Never Be Shared With Any Third Party.
About Writer [Blogging With Success]About Author SBA is a web designer and co-founder of BloggingWithSuccess.net. She publishes BPWebNews a place for Blogspot tips and tricks. You can also find her on Twitter. Read SBA's other posts. She's also published a couple of guest posts.

Leave a Comment

CommentLuv Enabled

{ 12 comments… read them below or add one }

Regular Blog Tips April 19, 2010 at 8:04 PM

Nice tips. I’m gonna install Widget Logic right now for my Wordpress.
Regular Blog Tips´s recent blog ..The Lazy Bloggers Post Generation Tool My ComLuv Profile

Reply

SBA April 20, 2010 at 3:26 AM

Hi Shubhkarman,
That’s what I call action! By the way, which widgets will you hide? Been meaning to ask are you planning to put up a favicon? How did you create your avatar?

Reply

memey April 20, 2010 at 2:52 PM

thats a grat idea..ilike it..thanks..
memey´s recent blog ..2010 Subaru EXIGA 2.0GT STI My ComLuv Profile

Reply

SBA April 23, 2010 at 4:46 PM

Memey, do you have other blogs where you plan to us this?

Reply

Creative Junkie April 20, 2010 at 6:36 PM

I USE WIDGET LOGIC!

Yes, I’m shouting, because it’s not often that I actually do something you post about, before you post about it!

Of course, I had no idea of all the other codes other than the homepage one and I had to Google myself to death to get that one, but hey! Baby steps, right?
Creative Junkie´s recent blog ..It’s too pretty to eat. Unless you’re starving. My ComLuv Profile

Reply

SBA April 23, 2010 at 4:50 PM

So glad to see you again! Google is a good walking stick so you’ve used it well. Just seeing your post titles in CommentLuv makes me start to giggle… I know what’s coming… fun.

Reply

alamin April 21, 2010 at 1:52 AM

Thanks another very nice post. You kill my time, when i entered your site i cant stop myself from reading post, huhu
alamin´s recent blog ..How to make a blog at blogger totally free? My ComLuv Profile

Reply

SBA April 23, 2010 at 4:55 PM

Now that’s a good to hear. I know you’re not just killing time, but putting tips into action (you did read that post about reading not making you successful, lol). Thanks for coming back!

Reply

strGraphics May 3, 2010 at 7:16 AM

Excellent share.., nice concept.

Thanks friend.

Reply

SBA May 3, 2010 at 5:21 PM

I tried to visit your site but there was a “500 – internal server error.’ Will try again later, but you might want to ask your webhost to investigate. Thanks for stopping by; hope you use the tip.

Reply

Cole May 21, 2010 at 9:23 AM

So I have no idea when you posted this because there’s no date on this page but I wanted to add my thoughts. I have edited my sidebar.php so the code that calls the sidebar looks like this (minus the lesser/greater thans cause I don’t know how it’ll show on your blog):

?php
$sidebar_index=1;
if ( is_page('Me') || $post->post_parent == '2168') {
$sidebar_index=2;
} elseif (is_page('Content') || $post->post_parent == '2175') {
$sidebar_index=3;
} elseif (is_page('Site') || $post->post_parent == '2172') {$sidebar_index=4;
} elseif (is_page('Links') || $post->post_parent == '2965') {
$sidebar_index=5;
}
?

?php
if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar($sidebar_index) ) : ?

It seems like this plugin does a similar thing in a different way. I have 5 sidebars with 4 or so widgets in each so having the separate sidebars in my dashboard is more useful than editing 20 widgets on one page. But I do like that you edit the widgets to specify where they show, rather than editing posts/pages (which would pretty much be impossible for me).
Cole´s recent blog ..Cell Phone Culture My ComLuv Profile

Reply

SBA May 21, 2010 at 5:38 PM

Cole, I think your sidebars are super smart! Great idea to hide all the sidebars, then dynamically show the one you want.. Thanks for sharing this approach.

Reply

{ 2 trackbacks }

Previous post:

Next post: