Widget Display Control  ON   OFF

Select a combination of options to control on which sections of your site this widget is shown.

> on Front Page

Categories

> on Posts in Category:
> Include sub-categories automatically

Pages

> on Pages:
> Include sub-pages automatically

Special Page Options
query_vars; $instance = conditional_widgets_init_instance($instance); if ($instance['cw_home_enable_checkbox']) { //box checked for home page logic takes priority by processing first switch ($instance['cw_select_home_page']) { case 0: //hide if front page if (is_front_page()) { if ($debug) {echo "[Widget hidden because front page.]

"; } return false; } break; case 1: //show if front page if (is_front_page()) { if ($debug) {echo "Showing because front page:
"; } return $instance; } break; case 2: //only show on front, hide otherwise if (is_front_page()) { if ($debug) {echo "Showing because front page:
"; } return $instance; } else { if ($debug) {echo "[ Widget hidden because not front page]

"; } return false; } break; } } $arr_pages = $instance['cw_selected_pages']; if ($instance['cw_pages_enable_checkbox'] && is_page()) { //box checked for caring about what pages $current_page_id = $wp_query->post->ID; //see if we care about subpages if ($instance['cw_pages_sub_checkbox'] == 1) { foreach($arr_pages as $page) { $args = 'child_of=' . $page; $newpages = get_pages($args); foreach ($newpages as $newpage) { array_push($arr_pages, $newpage->ID); } } } //if subpages count $match = false; if (in_array($current_page_id, $arr_pages)) { $match = true; } if ($match) { //we matched a page if ($instance['cw_select_pages'] == 1) { //and we're showing on matched pages - SHOW if ($debug) {echo "Showing because we're set to show on this page:
"; } return $instance; } else { //and we're hiding on matched pages - so HIDE if ($debug) {echo "[Widget hidden because this page wasnt chosen to have this widget displayed.]

"; } return false; } } else { //we did NOT match a page if ($instance['cw_select_pages'] == 1) { //and we're telling it to show on matched pages - so HIDE if ($debug) {echo "[Widget hidden because this is a page you told me to hid it on.]

"; } return false; } else { //we didn't match a page, and we told it to hide on those pages - so SHOW if ($debug) {echo "Showing because front page:
"; } return $instance; } } } //is_page && we care //see if we care about categories... (2/28/2012: AND if this page is related to categories...) $match = false; if ($instance['cw_cats_enable_checkbox'] && (is_single() || is_category())) { //starting point. haven't matched yet - checked categories. $arr_cats = $instance['cw_selected_cats']; //expand arr_cats to include subcats if ($instance['cw_cats_sub_checkbox'] == 1) { foreach($instance['cw_selected_cats'] as $cat) { $args = 'child_of=' . $cat; $newcats = get_categories($args); foreach ($newcats as $newcat) { array_push($arr_cats, $newcat->term_id); } } } //if including subcats $current_post_id = $wp_query->post->ID; //if this is a single_post if (is_single()) { //get the categories of the post $postcats = get_the_category($qvars['p']); foreach ($postcats as $cat) { if (in_array($cat->term_id, $arr_cats)) { $match = true; continue; } } } //if this is a categories archive page if (is_category()) { $cat = $qvars['cat']; if (in_array($cat, $arr_cats)) { $match = true; } } // Logic Processing now that we've determined whether or now we're a match if ($match) { //we matched a cat if ($instance['cw_select_cats'] == 1) { //and we're showing on matched cats if ($debug) {echo "Showing because I was told to show this on this category:
"; } return $instance; } else { //and we're hiding on matched cats if ($debug) {echo "[Widget hidden because I was told to show on certain categories - and this isn't one of em.]

"; } return false; } } else { //we did NOT match a cat if ($instance['cw_select_cats'] == 1) { //and we're telling it to show on matched cats - so HIDE if ($debug) {echo "[Widget hidden because this category doesn't match ones we were told to show on.]

"; } return false; } else { //we didn't match a cat, and we told it to hide on those cats - so SHOW if ($debug) {echo "Showing because this isn't one of the categories we were told to hide on:
"; } return $instance; } } } //if we care about categories //since 1.4 if (is_home()) { if ($instance['cw_posts_page_hide'] == 1) { if ($debug) {echo "[Widget hidden because this is the home page.]

"; } return false; } } // since 1.1 if (is_404()) { if ($instance['cw_404_hide'] == 1) { if ($debug) {echo "[Widget hidden because this is the 404 page.]

"; } return false; } } //if 404 // since 1.1 if (is_search()) { if ($instance['cw_search_hide'] == 1) { if ($debug) {echo "[Widget hidden because this is the search page.]

"; } return false; } } // if search // since 1.1 if (is_author()) { if ($instance['cw_author_archive_hide'] == 1) { if ($debug) {echo "[Widget hidden because this is an author archive page.]

"; } return false; } } // since 1.1 if (is_date()) { if ($instance['cw_date_archive_hide'] == 1) { if ($debug) {echo "[Widget hidden because this is a date archive page.]

"; } return false; } } //since 1.2 if (is_tag()) { if ($instance['cw_tag_archive_hide'] == 1) { if ($debug) {echo "[Widget hidden because this is a tag archive.]

"; } return false; } } //default to showing return $instance; } // register widget callbacks and update functions add_filter('widget_display_callback', 'conditional_widgets_widget'); add_action('in_widget_form', 'conditional_widgets_form', 10, 3); add_filter('widget_update_callback', 'conditional_widgets_update', 10, 2); /** * Helper function for displaying the list of checkboxes for Pages */ function conditional_widgets_page_checkboxes($selected=array()) { echo ""; } /** * Helper function for displaying the list of checkboxes for Categories */ function conditional_widgets_cat_checkboxes($selected = array()) { echo ""; } /** * Walker class for processing the Category checklists */ class Conditional_Widget_Walker_Category_Checklist extends Walker { var $tree_type = 'category'; var $db_fields = array ('parent' => 'parent', 'id' => 'term_id'); function start_lvl(&$output, $depth, $args) { $indent = str_repeat("\t", $depth); $output .= "$indent\n"; } function start_el(&$output, $category, $depth, $args) { extract($args); $name = 'cw-categories'; $output .= "\n
  • " . ''; } function end_el(&$output, $category, $depth, $args) { $output .= "
  • \n"; } } /** * Walker class for processing the Page checklists */ class Conditional_Widgets_Walker_Page_Checklist extends Walker { function __construct($selected = array()) { //$this->checked should be an array $this->checked = $selected; } var $tree_type = 'page'; var $db_fields = array ('parent' => 'post_parent', 'id' => 'ID'); function start_lvl(&$output, $depth, $args) { $indent = str_repeat("\t", $depth); $output .= "$indent\n"; } function start_el(&$output, $page, $depth, $args) { $output .= "\n
  • "; $output .= '"; } function end_el(&$output, $category, $depth, $args) { $output .= "
  • \n"; } } /** * Helper function for outputting the select boxes in the widget's form */ function conditional_widgets_form_show_hide_select($name, $value='', $only=false) { echo ""; } /** * Display CSS in admin head */ function conditional_widgets_css_admin() { // CSS and Javascript for HTML HEAD ?>