'',
'show_option_none' => __('No categories'),
'orderby' => 'name',
'order' => 'ASC',
'show_last_update' => 0,
'style' => 'list',
'show_count' => 0,
'hide_empty' => 1,
'use_desc_for_title' => 1,
'child_of' => 0,
'feed' => '',
'feed_type' => '',
'feed_image' => '',
'exclude' => '',
'exclude_tree' => '',
'current_category' => 0,
'hierarchical' => true,
'title_li' => __( 'Categories' ),
'echo' => 1,
'depth' => 0,
'include'=>'',
'taxonomy' => 'category',
'selected'=>false, //array of term names
'type'=>false, //false|radio|checkbox
'walker'=>false
);
$r = wp_parse_args( $args, $defaults );
$r['walker']=(bool)$r['type'];
if ( !isset( $r['pad_counts'] ) && $r['show_count'] && $r['hierarchical'] )
$r['pad_counts'] = true;
if ( isset( $r['show_date'] ) )
$r['include_last_update_time'] = $r['show_date'];
if ( true == $r['hierarchical'] ) {
$r['exclude_tree'] = $r['exclude'];
$r['exclude'] = '';
}
if ( !isset( $r['class'] ) )
$r['class'] = ( 'category' == $r['taxonomy'] ) ? 'categories' : $r['taxonomy'];
extract( $r );
if ( !is_taxonomy($taxonomy) )
return false;
if ((oqp_is_multiste()) && ($blog_id)) {
switch_to_blog($blog_id);
$categories = get_categories( $r );
restore_current_blog();
}else {
$categories = get_categories( $r );
}
$output = '';
if ( $title_li && 'list' == $style )
$output = '
' . $title_li . '';
if ( empty( $categories ) ) {
if ( ! empty( $show_option_none ) ) {
if ( 'list' == $style )
$output .= '- ' . $show_option_none . '
';
else
$output .= $show_option_none;
}
} else {
global $wp_query;
if( !empty( $show_option_all ) )
if ( 'list' == $style )
$output .= '- ' . $show_option_all . '
';
else
$output .= '' . $show_option_all . '';
if ( empty( $r['current_category'] ) && ( is_category() || is_tax() ) )
$r['current_category'] = $wp_query->get_queried_object_id();
if ( $hierarchical )
$depth = $r['depth'];
else
$depth = -1; // Flat.
if (!$r['walker'])
$output .= walk_category_tree( $categories, $depth, $r );
else
$output .= oqp_walk_category_tree( $categories, $depth, $r ); //radio or inputs
}
if ( $title_li && 'list' == $style )
$output .= '
';
$output = apply_filters( 'wp_list_taxonomy_'.$taxonomy, $output );
if ( $echo )
echo $output;
else
return $output;
}
//
// Helper functions
//
/**
* Retrieve HTML list content for category list.
*
* @uses Walker_Category to create HTML list content.
* @since 2.1.0
* @see Walker_Category::walk() for parameters and return description.
*/
function oqp_walk_category_tree() {
$args = func_get_args();
// the user's options are the third parameter
if ( empty($args[2]['walker']) || !is_a($args[2]['walker'], 'Walker') )
$walker = new Oqp_Walker_Term;
else
$walker = $args[2]['walker'];
return call_user_func_array(array( &$walker, 'walk' ), $args );
}
//
// Category Checklists
//
/**
* {@internal Missing Short Description}}
*
* @since unknown
*/
class Oqp_Walker_Term extends Walker {
var $db_fields = array ('parent' => 'parent', 'id' => 'term_id'); //TODO: decouple this
function start_lvl(&$output, $depth, $args) {
$indent = str_repeat("\t", $depth);
$output .= "$indent\n";
}
function end_lvl(&$output, $depth, $args) {
$indent = str_repeat("\t", $depth);
$output .= "$indent
\n";
}
function start_el(&$output, $term, $depth, $args) {
if (!$args['selected'])
$args['selected']=array();
extract($args);
if ( empty($taxonomy) )
$taxonomy = 'category';
if (!is_array($selected))
$selected=explode(', ',$selected);
$output .= "\n".'' . '';
}
function end_el(&$output, $term, $depth, $args) {
$output .= "\n";
}
}
?>