Multiple Sidebars the Right Way

Multiple Sidebars the Right Way

Multiple sidebars are becoming increasingly popular with specific sidebars being displayed only on specific pages or posts. How do they do it? Originally it’d be an if (ie if is homepage) and then include a PHP file, but WordPress has a better way. A built in better way. In this post we’ll learn how to add multiple sidebars the right way.

The old, rubbishy way

Back in the day, you’d have something like this:

<?php include (TEMPLATEPATH . '/single-sidebar.php'; ?>

Which isn’t too pretty. Because WordPress has a better way of doing things. Which is using the get_sidebar function that is normally used to get the sidebar.

The new, brilliant way

It’s really as simple as renaming your new fancy sidebar sidebar-something.php and then you can use the get_sidebar function like so:

<?php get_sidebar('something'); ?>

And that’s all there is to it. I would write more, but that’s essentially it. So I won’t. Enjoy your new found knowledge!

You should follow me on Twitter

Related Posts

Best Practices for Creating Unique Blog Posts

Best Practices for Creating Unique Blog Posts


Write Faster With WordPress’ Shortcodes

Write Faster With WordPress’ Shortcodes


10 More Tips To Improve Your Theme

10 More Tips To Improve Your WordPress Theme


WPShift

6 Comments - Add Yours!

  • Sara wrote on November 18, 2009 at 3:17 pm | Permalink

    Nice to know about, thanks!

  • Cracks wrote on December 16, 2009 at 8:31 am | Permalink

    So why exactly is the get_sidebar version is better?

    Is it just a “pretty” factor, or is it less load heavy? Please explain.

  • Rebecca wrote on January 12, 2010 at 4:06 am | Permalink

    Thanks, just the simple instructions I was looking for!

    • Alex Denning wrote on January 18, 2010 at 3:51 pm | Permalink

      Glad I could be a help!

  • Theo wrote on January 16, 2010 at 5:11 pm | Permalink

    Truly brilliant !
    Thanks

  • Ashfame wrote on February 11, 2010 at 5:19 pm | Permalink

    Yes you can have multiple sidebars that way but I bet you want them to be widgetized too. Refer to one of my post on my blog – How to have multiple widgetized different sidebars (http://blog.ashfame.com/2009/11/multiple-widgetized-different-sidebars/)

Post a Comment

Please take not of the comment policy.

Your email is never published nor shared.

*
*
User Gravatar