Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm trying to use the walker_category class in order to modify the HTML output of the wp_list_categories for several custom taxonomies, but the walker doesn't seem to 'work the tree'.

Here is my current code:

class Custom_Taxonomy_Walker extends Walker_Category {

function start_lvl( &$output, $depth = 0, $args = array() ) {
    $class = '"level-' . $depth . '"';
    $output .= sprintf( "\n<ul class=%s>", $class );
}
function end_lvl( &$output, $depth = 0, $args = array() ) {
    $output .= "</ul>\n";
}
function start_el( &$output, $object, $depth = 0, $args = array(), $current_object_id = 0 ) {
    if ($depth <= 1) {
        $class = "parent";
    }
    else {
        $class = "enfant";
    }
    $output .= sprintf( '<li class="%s">', $class );
}
function end_el( &$output, $depth = 0, $args = array() ) {
    $output .= "</li>\n";
}

}

and the call to wp_list_categories:

            foreach ($post_types as $post_type=>$post_tax) {
                $args = array(
                    'show_count'    => 1,
                    'hierarchical'  => 1,
                    'pad_counts'    => 1,
                    'taxonomy'      => $post_tax,
                    'walker'        => new Custom_Taxonomy_Walker);
                wp_list_categories ($args);
            }

Could someone provide a hint in the right direction? Thanks a lot for helping.

share|improve this question
    
Some strange rule prevents me to answer my own question less then some hours after I posted it! As I'll be leaving soon for several weeks, I want to say I've found the solution: I just had to put the term name (or whatever) in the output, and not to rely on the function to do it by itself... With something like $output .= "\n<li>" . $object->name; it does work. –  tosca Jun 8 at 14:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.