Wordpress Toggle Category widget set: Difference between revisions
No edit summary  | 
				No edit summary  | 
				||
| (5 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
== Toggle Category Widget Set ==  | |||
[http://thedigitalmachine.com/files/ToggleCategoryWidgets_0_3.zip Download v0.3]  | |||
'''Description'''  | |||
I have a [http://news.thedigitalmachine.com/category/chatter/ 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.  | I have a [http://news.thedigitalmachine.com/category/chatter/ 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.    | 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 [http://news.thedigitalmachine.com tech blog].  | ||
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.  | I've packaged the functionality into a set of Wordpress widgets, available for download [http://thedigitalmachine.com/files/widget_toggle_chatter.php 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   | * The plugin contains a hardcoded setting for the category number (2).  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   | * 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.  | * 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  | '''Instructions'''  | ||
# Download the plugin and extract the files into your plugins directory.  | # Download the plugin and extract the files into your plugins directory.  | ||
# Go to your Plugins page and activate the Toggle Chatter plugin.  | # Go to your Plugins page and activate the Toggle Chatter plugin.  | ||
# Go to your Design -> Widgets page and add the widgets to your sidebar.  | # Go to your Design -> Widgets page and add the widgets to your sidebar.  | ||
# Update your theme's index.php file as follows.  Right before the loop, add this block of code (changing the category number as needed):  | # Update your theme's index.php file as follows.  Right before [http://codex.wordpress.org/The_Loop the loop], add this block of code (changing the category number as needed):  | ||
  <?php    |   <?php    | ||
Latest revision as of 14:41, 29 July 2008
Toggle Category Widget Set
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
- Download the plugin and extract the files into your plugins directory.
 - Go to your Plugins page and activate the Toggle Chatter plugin.
 - Go to your Design -> Widgets page and add the widgets to your sidebar.
 - 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"); 
    }
} 
?>