Skip to Navigation

WordPress: Certain Widgets on Certain Pages

Printer-friendly version

WordPress and Drupal are similar in a lot of ways. They're both extremely popular, powerful, and flexible frameworks. They both have minimal cores, but were built from the ground-up to handle tons of extensibility. Even though WordPress has been traditionally thought of as a blogging system, it's gradually shaping into a more refined, full-featured CMS. WordPress Plugins like Pods CMS and Flutter are opening the flood gates of potential, just like how the CCK and Views modules have revolutionized Drupal.

Drupal - Blocks

Drupal includes things called "Blocks", which are chunks of code/HTML that you can stick in various "regions" of your site (e.g. Header, Footer, Content Top, etc). With blocks, you can choose which pages these blocks appear on, or which pages to exclude them from appearing on.

WordPress - Widgets

WordPress has similar things called "Widgets". The main thing missing with Widgets as opposed to Blocks is the ability to display specific Widgets on specific pages. Regardless, Widgets are relatively simple to implement. You first add some PHP code in functions.php to define new "regions" to place widgets into.

<?php if (function_exists('register_sidebar')) { register_sidebar(array( 'name'=>'My Footer', 'before_widget' => '', 'after_widget' => '', 'before_title' => '<h4>', 'after_title' => '</h4>' )); }

 

Then, it's a matter of adding some code to your WP Template file (e.g. index.php) to display this custom Widget region:

<?php dynamic_sidebar('My Footer'); ?>

WordPress Plugin: Widget Block

I created a plugin so that you can treat WordPress widgets more like Drupal blocks. Specifically, you can choose which pages a certain widget will appear on (or be excluded from). This plugin also prevents you from needing to create many slightly different Widget regions. The plugin is called Widget Block; give it a try!

Widget Block