Posted: February 5, 2012 in Web
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.
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.
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
- 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.