Vandelay Website Design Blog

Enhanced Sidebars with Dynamic Content

After writing Effective Use of Blog Sidebars a couple of weeks ago I decided to look into the topic of dynamic sidebars. Typically, most blogs will us a standard sidebar for the entire site. WordPress users have a lot of potential functionality that is rarely used in terms of creating various sidebars and displaying them in different situations.

For example, when I was creating the theme for DesignM.ag I needed to have slightly different sidebars according to the category of the post. You can see the differences by looking at a standard blog post, a post in the community news category, and a post in the gallery category. For items in the news category I wanted a brief introductory paragraph with a button to submit news, followed by a list of recently published news items. On posts in the gallery I wanted the same thing, except for the gallery category instead of the news category. Posts in all other categories have a list of categories followed by recent news items. As a result there are three different left sidebars that are shown depending on the category of the post.

Why Would You Want Dynamic Sidebars?

Every blog visitor has different habits, but many tend to ignore sidebars because they are always the same. Mixing things up and keeping the contents of the sidebar relevant to the post can make them a bit more likely to be noticed. In short, blog sidebars are often ineffective because they are:

  • Boring
  • Outdated content (not changed frequently)
  • All the same throughout the blog
  • Not relevant to the rest of the page
  • Full of too many links with a cluttered appearance

What Can You Do to Fix Ineffective Sidebars?

Dynamic sidebars can improve just about all of the situations mentioned above. They’re not as boring because they change as the visitor moves through the site, they’re more relevant to the content of each page, and they won’t need to be as cluttered because only the relevant information is displayed on each page (as opposed to cramming everything into one generic sidebar).

Dynamic Sidebars in Action

Since I was writing a post about dynamic sidebars I figured I should put them into action on this blog as well. So far I’ve only made two changes to the standard sidebar, but more may be coming.

First, I added a small box of text in the right sidebar on posts in the Social Media category. I have a blog called Traffikd where I write primarily about social media marketing and blogging, so I decided to add a promotional statement for Traffikd on these posts since it’s relevant to most readers within that category (these are mostly older posts before I launched Traffikd). You can visit the post 50+ Designers to Follow On Twitter to see the change in action. The image below shows the block of text, it appears right after the banner ads and before the Popular Posts section in the sidebar.

Dynamic Sidebar

Second, based on the popularity of the collections of Photoshop tutorials, I decided to link them together in a different way. If you visit 40 Photoshop Tutorials for Lighting and Abstract Effects you’ll see a small list appear, again it’s in the right sidebar between the banners and the Popular Posts. You’ll see the headline “Photoshop Tutorials”, and then it links to all five of the collections of tutorials. You’ll also see a link for the post that you’re viewing because the 5 links are the same on all of the posts. It would be possible to set it up to only include links to the other four posts, but that would take some additional coding and I decided to keep it lighter.

Dynamic Sidebar 2

It’s too early to tell if these minor changes have any noticeable effect in terms of click-throughs and enhanced navigation, but this just shows that there are plenty of options for creating your own dynamic sidebars.

Different Strategies for Creating Dynamic Sidebars

With WordPress you have some different options for achieving the end result of improved sidebars. Fortunately there are a number of good tutorials out there for these different techniques (plus the Codex), so I’ll try to point you in the right directions in addition to giving some of my own thoughts.

1. Use a conditional tag and a php include to insert an item.

This is the method that I used for both of the changes to the Vandelay sidebars. Using the first example, the php conditional statement essentially says, “if the post being shown is in the social media category, display the contents of the socialside.php file. If the post is in any other category, ignore this statement and just display the standard sidebar.”

This code is placed in the right sidebar php file exactly where I want the box of text to appear. The socialside.php file contains only one paragraph of text wrapped in paragraph tags and given a CSS class. The class of course is used to style the paragraph with the darker background and the border.

Here’s the code I’m using in my sidebar for this:

<?php if ( in_category(13) ) { include ('socialside.php'); } ?>

You can use this to do any number of different things with your sidebar if you get creative. Of course, you’ll want to change the number in the category to suit your needs. In my situation the social media category is number 13, but you may want to use another number, and you can exchange socialside.php for whatever you want to include.

In the second example that I’m using on this blog, I’m also using a conditional statement but in a different way. I wanted to display the Photoshop links only on 5 specific posts (probably more in the future when they are published). Unfortunately, these posts are not in their own category, they’re in the Design category, which has a ton of other posts where I don’t want these links to appear. This isn’t really a problem though, because you can also use conditional statements for specific posts instead of category. Each post has its own unique number, so it’s almost the same as the previous example.

Here’s the code I’m using:

<?php if ( is_single(324, 299, 279, 275, 242) ) { include ('ps.php'); } ?>

The “is_single” tells WordPress to base the conditional statement on the number of the individual post being displayed. The three-digit numbers are the numbers of the specific posts, and then you have the include for the ps.php file, which simply contains the image for the headline and then the links. I can easily add another post to this statement if I was to publish another collection of tutorials, and I could add the new link in the ps.php file as well.

For more on conditional tags see:

2. Create separate sidebars for the front page, single posts, pages, archives, etc.

WordPress uses several different files (assuming your theme contains all of these files) based upon the part of the site/blog that is being viewed. The homepage layout is controlled by the index.php file. The layout of a single page is controlled by the single.php file. Layouts of pages (not posts) are controlled by page.php, and so on. Each of these files will likely contain the code to grab the contents of the sidebar. For example, mine uses:

<?php include (TEMPLATEPATH . '/l_sidebar.php'); ?>

If you want a different sidebar to appear on your frontpage as opposed to your individual posts, all you have to do is create a second sidebar file, l_sidebar2.php. Now, if you want that sidebar to appear on individual posts you can use this code in your single.php file:

<?php include (TEMPLATEPATH . '/l_sidebar2.php'); ?>

It’s a pretty simple change, but it gives you several different options.

3. Control the Style of the sidebar by switching the stylesheet

It’s also possible to use your stylesheet to give your sidebar different looks for various categories. It’s not an approach that I’ve used before, so I’ll point you to Using WordPress Categories to Style Posts from Lorelle via a guest author.

For lots of great information that can help with dynamic sidebars, see:

Some Ideas for Dynamic Sidebars

There’s really no limit to what you could do with dynamic sidebars. Here are a few of my ideas:

  • Show author information
    This wouldn’t require coding strategies listed above, but if you have multiple authors you could include the author bio in the sidebar to change things up a bit from post-to-post.
  • Include a relevant ad or affiliate link
    Maybe you have a specific post or category that would be great for promoting a specific affiliate product. You can use the strategy of conditional tags and includes to put it wherever you want.
  • Make a series out of your posts
    This is essentially what I’m doing with the Photoshop posts. You could adapt this strategy to fit your own content and funnel traffic through related posts on a specific topic.
  • Create a call for subscriptions on high-traffic posts
    Do you have a few specific posts that get a lot of search engine traffic consistently? Why not use a conditional tag and an include to put an extra call for subscriptions in your sidebar? I may try this approach myself.

What Ideas Do You Have?

Are you using dynamic sidebars on your own blog? If so, please share your approach with us. What other ideas do you have for creating dynamic sidebars?

Originally Published July 23rd, 2008

26 Responses

  1. Janko | July 24th, 2008 at 4:04 am

    What a great article. It made me think about my sidebar… I will have to do something about it

  2. Evan Skuthorpe | July 24th, 2008 at 5:50 am

    Varied sidebars are the way to go. It makes sense to have relevant content on your side bar for whatever particular section of the site you’re in.

  3. VandelayDesign | July 24th, 2008 at 7:08 am

    Janko and Evan,
    Thanks for your comments.

  4. liam | July 24th, 2008 at 7:14 am

    Completely agree, nice tips & Ideas, must admit I’ve neglected my sidebar a little. I wanted it to have complete control over the content so made everything static apart from a few sections, but I may need to take another look into this at some point :)

  5. Dwayne Charrington | July 24th, 2008 at 6:03 pm

    You know what? This article actually inspired me. Dynamic sidebars are a fantastic idea, and definitely a good way to keep your visitors interested with fresh content.

    Thanks for the inspiration.

    - Dwayne.

  6. Sasa Bogdanovic | July 24th, 2008 at 6:35 pm

    One thing that bothers me much with WordPress is that category Ids have to be hardcoded, like in

    <code>
    <?php if ( in_category(13) ) { include (’socialside.php’); } ?>
    <code>

    It is true that changing them is insane as links to the pages of that category would result in 404, but having dependency on meaningless hard-coded values is neither semantic nor sane.
    This also makes the theme practically unusable on other blogs for obvious reason that categories will not be the same.

    Steven, don’t get me wrong, nothing against your example. Sadly, this is the way WordPress works.

  7. Vandelay Design | July 24th, 2008 at 6:45 pm

    Liam,
    I’m with you. I like control over the sidebar elements so I use mostly static items, plus it’s less strain on the server and the database. Some changes here and there may or may not help. We’ll see.

    Dwayne,
    Good! Thanks for the feedback.

    Sasa,
    No offense taken. The method shown above is what I use, but if I’m not mistaken I think you can also use the slug of the category. Still has some limitations like you mentioned. WP is definitely not perfect, but for a free CMS I think the pros far outweigh the cons (mostly the community and the endless options).

  8. Thursday Links Roundup #4 - Putting Blogs First | July 25th, 2008 at 12:29 am

    […] Enhanced Sidebars with Dynamic Content - For WordPress users, this tutorial describes how to use conditional tags to make your sidebar come to life. A technique used here on PBF too. […]

  9. Keith Gill | July 26th, 2008 at 5:06 am

    This article actually inspired me. Dynamic sidebars are a fantastic idea, and definitely a good way to keep your visitors interested with fresh content.

  10. Anthony | July 27th, 2008 at 7:18 am

    Cheers for the info dude, its really helpful!

  11. flisterz | July 27th, 2008 at 7:20 pm

    Definitely agree with Sasa. That is the most disappointing part when I’m coding for a WP theme.
    Anyhow, this is a great article. Sidebar should be as dynamic as the main part of the site. :)

  12. An Engaging Collection Of Links - This Month In SEO - 7/08 | TheVanBlog | Van SEO Design | August 7th, 2008 at 3:18 pm

    […] Enhanced Sidebars with Dynamic Content […]

  13. Jeriko | September 4th, 2008 at 5:09 pm

    Since WordPress 2.6, get_sidebar() accepts a sidebar name as parameter, which then looks for a file sidebar-name.php in the theme folder. E.g. get_sidebar(’singleview’) loads sidebar-singleview.php as a sidebar, with sidebar.php as a fallback if the wanted sidebar isn’t available.

  14. Evaluating the Effectiveness of Your Blog Theme :: Antilogic Media | September 17th, 2008 at 3:30 am

    […] more on sidebars, see Enhanced Sidebars with Dynamic Content and Effective Use of Blog […]

  15. Chad | September 22nd, 2008 at 1:32 pm

    Good stuff. Thanks for the tips and other ideas. I first really delved into using dynamic sidebars for my biz site (click my name). I call different includes depending on the page, or category being viewed. It really does help break the “same old content” feel, that normally sits in a sidebar.

  16. 30+ (More) Most Wanted Wordpress Tips, Tricks and Hacks | Wordpress | October 4th, 2008 at 4:06 am

    […] Sidebar With Dynamic Contents […]

  17. Mas de 30 Wordpress Tips, Tricks y Hacks | Xtreme News | October 4th, 2008 at 11:32 pm

    […] Sidebar With Dynamic Contents […]

  18. Alan | October 5th, 2008 at 5:23 am

    Another alternative - my own plugin to make all widgets appearance conditional

    http://wordpress.org/extend/plugins/widget-logic/

  19. 30+个非常有用的WordPress技巧(一) | 小墨|博客 | October 6th, 2008 at 2:39 am

    […] 3、Sidebar With Dynamic Contents 动态侧边栏的实现,不同页面显示不同的侧边栏(PS:之前介绍过的WordPress Widget Changer也可以实现这个功能) […]

  20. links for 2008-10-07 « Dexle | October 9th, 2008 at 11:02 am

    […] Enhanced Sidebars with Dynamic Content (tags: wordpress webdesign) […]

  21. EggFire Inc » Blog Archive » 30 Most Wanted Wordpress Tips, Tricks and Hacks | October 14th, 2008 at 12:13 pm

    […] Sidebar With Dynamic Contents […]

  22. Tutto Games | October 18th, 2008 at 3:33 pm

    […] Sidebar con contenuto dinamico […]

  23. 30+ (More) Most Wanted Wordpress Tips, Tricks and Hacks | Web Burning Blog | October 22nd, 2008 at 3:31 am

    […] Sidebar With Dynamic Contents […]

  24. 30+ (More) Most Wanted Wordpress Tips, Tricks and Hacks | Web Burning Blog | October 22nd, 2008 at 3:31 am

    […] Sidebar With Dynamic Contents […]

  25. 20+ plugin per Wordpress e non solo | Area3000 | October 27th, 2008 at 2:03 am

    […] Sidebar con contenuti dinamici […]

  26. 10 Things to Do with Your Feed Footer | Traffikd | November 17th, 2008 at 10:23 pm

    […] screen space and improve the effectiveness of the blog as a result. Whether you’re working to improve your sidebar in effort to increase pageviews, adding related links at the end of your posts to build internal […]

Leave a Reply