Last active
December 11, 2015 16:18
-
-
Save jesgs/4626596 to your computer and use it in GitHub Desktop.
Add checkboxes to categories using a Walker class and wp_list_categories
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* My Project | |
* | |
* @package MyProject | |
* @subpackage JesGs_Walker_Category | |
* @author Jess Green <[email protected]> | |
* @version $Id$ | |
*/ | |
/** | |
* JesGs_Walker_Category | |
* | |
* @todo move contents of start_el method to separate template. | |
* | |
* @package JesGs_Walker_Category | |
* @author Jess Green <[email protected]> | |
*/ | |
class JesGs_Walker_Category extends Walker_Category | |
{ | |
/** | |
* @see Walker_Category::start_el | |
*/ | |
public function start_el(&$output, $category, $depth, $args, $current_object_id = 0) | |
{ | |
extract($args); | |
$cat_name = esc_attr( $category->name ); | |
$cat_name = apply_filters( 'list_cats', $cat_name, $category ); | |
$cat_slug = esc_attr( $category->slug ); | |
if ( 'list' == $args['style'] ) { | |
$output .= "\t<li"; | |
$class = 'cat-item cat-item-' . $category->term_id; | |
if ( !empty($current_category) ) { | |
$_current_category = get_term( $current_category, $category->taxonomy ); | |
if ( $category->term_id == $current_category ) | |
$class .= ' current-cat'; | |
elseif ( $category->term_id == $_current_category->parent ) | |
$class .= ' current-cat-parent'; | |
} | |
$output .= ' class="' . $class . '"'; | |
$output .= "><input type=\"checkbox\" name=\"$cat_slug\" /> $cat_name"; | |
} else { | |
$output .= "\t$cat_name<br />\n"; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Perfect! Thank you so much.