Per Page Sidebar Blocks plugin for WordPress

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/

[hr]

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.

[hr]

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.

[hr]

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.

[hr]

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]
<?php if( function_exists( ‘ppsb_show_sidebars’ ) ) echo ppsb_show_sidebars(); ?>
[/php]

Obviously, you will have to pull the sidebar in your page templates (page.php, index.php, etc.) which require sidebar output.
[php]
<?php get_sidebar() ?>
[/php]

[hr]

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.

[hr]

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.

[hr]

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

[hr]

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.
18 replies
  1. Sam Rae
    Sam Rae says:

    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?

    Reply
    • Jason Cross
      Jason Cross says:

      @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?

      Reply
  2. Angus
    Angus says:

    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…

    Reply
    • Jason Cross
      Jason Cross says:

      @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?

      Reply
  3. Paul
    Paul says:

    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.

    Reply
  4. Sam Rae
    Sam Rae says:

    @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%5B%5D=mark&ppsb_side%5B%5D=register&ppsb_side%5B%5D=news&ppsb_side%5B%5D=Facebook&ppsb_side%5B%5D=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.

    Reply
  5. christele
    christele says:

    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

    Reply
    • Jason Cross
      Jason Cross says:

      @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?

      Reply
  6. beefchimi
    beefchimi says:

    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,

    Reply
    • Jason Cross
      Jason Cross says:

      @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.

      Reply
  7. Chris
    Chris says:

    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!

    Reply
    • Jason Cross
      Jason Cross says:

      @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.

      Reply
  8. Aron
    Aron says:

    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

    Reply
  9. Jason Cross
    Jason Cross says:

    @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.

    Reply

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *