Last active
August 29, 2015 14:02
-
-
Save wvega/b32d52c404d98c71fce4 to your computer and use it in GitHub Desktop.
Categories List Walker for WEN Team (AWPCP's Issue #833)
This file contains 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 | |
if ( ! class_exists( 'Walker' ) ) { | |
require_once( ABSPATH . '/wp-includes/class-wp-walker.php' ); | |
} | |
if ( class_exists( 'Walker' ) ) { | |
class WEN_CategoriesListWalker extends Walker { | |
protected $options = array(); | |
public function __construct() { | |
$this->db_fields = array( 'id' => 'id', 'parent' => 'parent' ); | |
} | |
public function configure( $options = array() ) { | |
$this->options = wp_parse_args( $options, array( | |
'show_listings_count' => true, | |
) ); | |
return true; | |
} | |
public function start_lvl( &$output, $depth = 0, $args = array() ) { | |
$output .= '<ul class="dropdown-menu sub-menu">'; | |
} | |
public function end_lvl( &$output, $depth = 0, $args = array() ) { | |
$output .= '</ul>'; | |
} | |
public function start_el( &$output, $category, $depth = 0, $args = array(), $current_object_id = 0 ) { | |
$element = '<li class="cat-item"><a href="[category-url]">[category-name]</a> [listings-count]'; | |
$element = str_replace( '[category-url]', esc_attr( url_browsecategory( $category->id ) ), $element ); | |
$element = str_replace( '[category-name]', esc_attr( $category->name ), $element ); | |
$element = str_replace( '[listings-count]', $this->render_listings_count( $category ), $element ); | |
$output .= $element; | |
} | |
private function render_listings_count( $category ) { | |
return $this->options['show_listings_count'] ? '(' . $category->listings_count . ')' : ''; | |
} | |
public function end_el( &$output, $object, $depth = 0, $args = array() ) { | |
$output .= '</li>'; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment