Wordpress Toggle Category widget set

From Bitpost wiki

Toggle Category Widget Set

Download v0.3

Description I have a Chatter category 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. See it in action on my tech blog.

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.

Current status

  • The plugin contains a hardcoded setting for the category number (2). You'll have to edit the plugin directly until I add widget settings.
  • The plugin contains hardcoded text for the toggle ("Include chatter"). You'll have to edit the plugin directly until I add widget settings.
  • The plugin contains a hardcoded path to the plugins directory (/wp-content/plugins). Edit as needed until I update.
  • The plugin helper contains a hardcoded URL for the cookie (news.thedigitalmachine.com). Edit as needed until I can figure out an easier way.
  • I have some CSS markup cleanup to do in the plugin. You can do it yourself 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"); 
    }
} 
?>