While working on a WordPress theme for a cliënt he stated that he wanted to have page dependent content in the sidebar. In other words, a sitewide widget wouldn’t do because he wanted to hook widgets to certain pages, posts or categories. For example: the homepage showed widget #1 while the contact and the about-me page showed widget #2.
I’ve started looking into some dynamic / conditional widget plugins. Some worked pretty good, some were flawed and most were just crap. These are the ones that I found to be quite helpful and with decent code quality, they might be of use to you too.
This is my absolute favourite, although it might not be the best choice if you’re installing it so your cliënt (with no PHP knowledge) can use it later on. This plugin adds one small (but o so powerful) input field beneath every widget where you can specify any of WordPress’ conditional tags. This makes it possible to restrict a certain widget to a certain post, multiple posts, pages, categories, basically anything you like.
Of course, the downside is that the plugin user needs to know a thing or two about WordPress conditionals or PHP in general. If this isn’t the case you might be better of with one of the other plugins in this article. If the intended user has knowledge or is willing to look into WP Conditionals I highly suggest using this plugin though, as there are practically no limits.
This plugin adds some display options to all active widgets where you can specify some basic conditionals, as you can see in above screenshot. The nice touch is the textarea where you can specify certain URL’s to show the widget on. You are not limited to one URL and that makes this widget a perfect choice for users with no knowledge of WordPress conditionals. You can use some wildcards to match multiple URL’s with just one rule.
Like widget context, this plugin adds display options to all your active widgets where you can apply some conditionals where to show or hide the widget. Although you can’t restrict widgets to certain posts, you can add conditionals to show or hide the widget at certain category archives (+ posts inside that category) and certain pages only.
The code quality is above average (there is some crap out there..), it’s ease of use is perfect for cliënts with no understanding of PHP / HTML / any other webdevelopment language. All that’s needed is some basic logic.
With either one of these 3 plugins you should be able to create a one-to-many relationship between widgets and posts. Do you know a plugin that takes care of creating ‘dynamic widgets’ in a neat and easy-to-use way that isn’t covered in this post? Let me know in the comments!
If you’re looking for a way to display content from your post in a widget area (a one-to-one relationship), i’m actually thinking about developing a plugin for this. There are some out there already, but the ones i’ve looked at are crappy coded and do not support visual editors. Like the idea? Let me know, I won’t make it if you won’t use it!