Posted: February 5, 2012 in Web

Per page sidebar blocks banner

Download Per Page Sidebar Blocks plugin for WordPress

This plugin is being submitted to the WordPress repository. For now, you can download it here: Download Per Page Sidebar Blocks v1.0

The plugin is now available in the WordPress repository: http://wordpress.org/extend/plugins/per-page-sidebar-blocks/


Background and goals of this plugin

Part of offering WordPress as a CMS to my clients involves giving them as much control over the future of their website as possible. One pitfall I experience is offering per-page sidebar customization.

Sidebar templates and conditionals

I find myself creating several sidebar-name.php templates and using conditionals to display them where I want. Functions like is_page(), is_tree(), is_ancestor(), is_single(), etc. let me plan ahead for which sidebars should show on which pages. However, these functions do not truly allow customizing sidebar output for pages created in the future outside the scope of my preemptive conditionals.


Per page sidebar blocks checkboxes

Page-specific blocks of content in the sidebar

Per Page Sidebar Blocks lets you, the theme developer, create several sidebar templates using WordPress’ naming convention sidebar-name.php. (detailed in WordPress’ codex)

Automatically finds your sidebar templates

PPSB will scan the current theme’s root directory for all your sidebar templates and let you decide which ones get displayed on each individual page by simply checking a box on that page’s Edit area.

*Please note, this plugin will not search a child theme’s parent directory for sidebar-name.php files. These files must reside directly within the currently-active theme’s root directory.


Per page sidebars settings

Control the display order

Sidebar block control would not be complete without the ability to specify a display order.

Drag and drop

Just drag and drop each item into place on the PPSB Settings page (under the Settings menu), and see your changes reflected on the frontend. Changes are saved immediately via ajax, so no save button is necessary.

Sitewide display order

Your specified display order is sitewide, not page-specific. I currently have no plans of offering page-specific display orders.


Integrate into your theme

Integration is very simple. Put the following code into your sidebar.php file. This line checks if the plugin is activated, then shows enabled sidebars (if a box is checked) on the page being viewed.

<?php if( function_exists( 'ppsb_show_sidebars' ) ) echo ppsb_show_sidebars(); ?>

Obviously, you will have to pull the sidebar in your page templates (page.php, index.php, etc.) which require sidebar output.

<?php get_sidebar() ?>

Why is this sidebar plugin different?

There are other solutions that offer sidebar content control per page, but PPSB approaches the problem differently.

I don’t like widgets

Widgets don’t offer the level of consistent control that I need in the markup, and they open the door for my client to unintentionally “break” their website at some point. Client control is great, but too much control can introduce problems.

Custom sidebar building blocks

Instead of simply letting you select a full sidebar for a page (which you could certainly setup using this plugin), I go a step further and let you create different blocks of content. Let’s say your client has a list of Company Partner’s logos, and they want to list them on the About and Services pages. Rather than create a specific sidebar for each of those pages, create a sidebar-partners.php block and just enable it on every page it’s needed; use sidebar templates as building blocks to customize sidebar content as needed.

Just another tool

This solution is not ideal for every situation. For instance, your client may be confused if you have a 1 column page template, and they overlook that sidebars are not meant to be displayed on such pages. It may also become tedious to rebuild the sidebar for every page, whereas conditionals would automate this process. Then again, you could mandate certain blocks with conditionals and let your client control the others.

Hopefully, though, it’s niche of functionality will be suitable for some projects.


How does it work?

For those that are interested, you will notice the sidebar values are reiterated in the Custom Fields box; the checkboxes assign a yes or no value, but with a much more intuitive interface for your clients. The visibility of each sidebar template is stored in the wp_postmeta table of the database, and WordPress offers nice functions – get_post_meta() and update_post_meta() – to pull it all together.


Future goals of this plugin

  • Set certain sidebar blocks to be visible by default on all pages
  • Set certain sidebar blocks to be hidden from the Edit Page’s checkbox list

Known issues

  • PPSB visibility (the checkboxes on each page) is forgotten after the first time you save a new page. You have to check the sidebar blocks again AFTER saving, then save the page again.

I graduated from LSU with a B.F.A. in Graphic Design and a minor in Art History. My passions are web design and front-end development with over 10 years of experience.


1 Trackbacks/Pingbacks
  1. Pingback: Per Page Sidebar Blocks | Best Plugins - wordpress – widgets – plugin 2012 on April 20, 2012
18 Responses to Per Page Sidebar Blocks plugin for WordPress
  1. Sam Rae

    Hi Jason. I installed your plugin recently and it works fine, except that the reordering doesn’t work. Whatever order I drag the sidebar boxes into, they don’t save, and revert to the original order on a refresh. I’ve updated to the latest versions of WordPress and your plugin, and no luck. Any suggestions?

  2. Jason Cross

    @Sam Rae – I just tested the reordering again and it’s working fine on my end; reordering even works fine in IE7. Is there maybe a caching plugin (or another) interfering on your end?

  3. Angus

    Hi Jason,

    Great plugin – and great idea – But I’m having the same problem as Sam Rae did. I can’t change the order at all. It picks up each sidebar in the order that I created them in. And no matter what I do – I can’t get it to change to a different order… Do you know if Sam Rae got it working and how? Thanks…

  4. Jason Cross

    @Angus – I have not heard back from Sam Rae.

    Can you open Console (F12 in Chrome, Firebug in Firefox) on the P/P Settings page to see if there is an error when you move one?

    To retest this, I just installed a fresh copy of WordPress using the TwentyEleven theme, installed PPSB, added the function to the bottom of page.php, and created 2 test sidebar block templates. They’re reordering just fine. Can you do these same steps on your server?

  5. Paul

    Hi Jason. Just trying to set up the plugin. I might sound stupid but how to create necessary sidebar templates using WordPress’ naming convention sidebar-name.php? Got no idea, please help. Thanks.

  6. Jason Cross

    @Paul – The naming convention and usage I’m referring to is detailed here: http://codex.wordpress.org/Function_Reference/get_sidebar. You will have to make these files in your current theme’s root directory.

  7. Sam Rae

    @Jason — Thanks for getting back to me. Sorry for not replying earlier! The re-ordering seems to be working on and off for me now. I had to manually adjust some values in the MySQL database, and then it worked fine again. There were some massive numbers appearing in the database for the value: the entries went nicely from about 1 through to 4, and then went crazy, with figures in the 2000–3000 range.

    I looked at the Javascript console in Chrome when trying to reorder, and I got the following error:

    GET http://exalt.org.au/wp-content/plugins/per-page-sidebar-blocks/ppsb_process_sortable.php?ppsb_side=mark&ppsb_side=register&ppsb_side=news&ppsb_side=Facebook&ppsb_side=CCOWALogo 404 (Not Found)

    Thanks for the help! Apart from this problem, I’m loving the plugin—by far the most sensible sidebar plugin around, in my opinion.

  8. christele

    Good morning Jason,
    Your plugin works great; I seem to be able to create a custom sidebar for each page; however, I wanted my client to use those as templates in order for them to update the sidebar content themselves. If you plugin cannot do so, Do you know of any plugins that might do so?I have been working on these for days and can’t seem to find a solution…
    Thank you,
    christele

  9. Jason Cross

    @Christele – You should look into the Improved Include Page plugin. You could setup a page, reference it in a sidebar block, then let the user control the content within that block via the page AND whether it’s visible on a page with the PPSB plugin’s checkboxes. Does that make sense?

  10. beefchimi

    Hello,

    I am trying to use more than 1 sidebar on a single page. It only shows one at a time however.

    If I select sidebar-blog.php, that is what gets shown.

    If I select both sidebar-blog.php and sidebar-ads.php, only the top most sidebar (sidebar-blog.php) gets shown. When I uncheck sidebar-blog.php, my ads show up.

    Any idea what could be the issue?

    Also, the sidebars don’t seem to show up at all on my blog page (I have a static homepage, so Blog is a separate page which uses the index.php)

    Thanks,

  11. Chris

    Jason,
    I am having trouble with the options showing up in the “appearance” section of my wordpress admin site.
    I have checked and there is a sidebar.php in the root directory. And I made a test sidebar by copying the original Sidebar.php and adding the line “”

    I am not sure if I am putting in the correct place or not. But I am not getting the option to include and exclude any sidebar blocks.

    any help is greatly appreciated!

  12. Jason Cross

    @beefchimi – I have not come across the issue you’re describing. The function just runs through the items and displays if it’s checked. Multiple checks should not affect anything. Feel free to email me your admin url, login credentials, and ftp info if you’d like me to have a look. I’m definitely interested in resolving any bugs with the plugin.

  13. Jason Cross

    @Chris – The options should show under the Settings tab, not Appearance. Then when you have sidebars available, you should see some checkboxes on a page’s edit area.

    When you say you’re putting sidebar.php in the root directory, where are you referring? It should be in /wp-content/themes/yourtheme/. Can you also clarify what you did to create a test sidebar? All I see is that you copied sidebar.php and added “”. Copying the original sidebar.php defeats the purpose of the plugin. You should just create a new file named sidebar-something.php and put some content into there.

  14. Jason Cross

    @Sam Rae – Thanks for setting me up with a test install so I could see your issue. I believe it’s resolved, and the update is committed to v1.0.3.

  15. Aron

    Hi Jason

    Im having the same issue as beefchimi.

    My sidebar only displays the first sidebar that is checked.

    could you perhaps post how you solved this issue?

    Best regards Aron

  16. Jason Cross

    @Aron,

    beefchimi never did get back with me on his issue. Are you able to email me any sort of temporary admin credentials and FTP access to that or a clone of that site? I’d love to solve this bug if I can.

  17. Aron

    That would be greatly appreciated. what email should i send the info to?

Leave a comment

Did this article help you? Do you have a different opinion? Feel free to leave a comment or ask questions.