Wordpress Toggle Category widget set

From Bitpost wiki
Revision as of 04:45, 29 July 2008 by M (talk | contribs) (New page: I have a <a href="http://news.thedigitalmachine.com/category/chatter/">Chatter category</a> on my tech blog that's really just for my own notes-to-self. And sometimes I want to see it, so...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

I have a <a href="http://news.thedigitalmachine.com/category/chatter/">Chatter category</a> on my tech blog that's really just for my own notes-to-self. And sometimes I want to see it, sometimes I don't. And I certainly don't want first-time visitors to have to see it.

The solution I came up with was to provide a persistent toggle that would turn on/off the Chatter content. It starts "off", but any blog visitor can toggle it at any time. I've packaged the functionality into a set of Wordpress widgets, available for download here as a plugin.

There are three widgets in the plugin: the toggle itself, and two widgets that reflect the toggle state, a category list and a list of recent posts.

NOTE: Current status:

  • The widgets contain hardcoded settings for the category number. You'll have to edit the plugin directly until I add widget settings.
  • I have some CSS markup cleanup to do. You can do it yourself in the plugin if you're faster than me.  :>
  • You will want to modify your theme's index.php file to reflect the toggle's state. This is easy, and covered in the instructions.

Instructions:

  1. Download the plugin and extract the files into your plugins directory.
  2. Go to your Plugins page and activate the Toggle Chatter plugin.
  3. Go to your Design -> Widgets page and add the widgets to your sidebar.
  4. Update your theme's index.php file as follows. Right before the loop, add this block of code (changing the category number as needed):
<?php 
$include_chatter = $_COOKIE['chatter'];
if (is_home()) 
{ 
    if($include_chatter != 'yes') 
    {
        query_posts($query_string . "&cat=-2"); 
    }
} 
?>