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 haven't been able to find what I'm looking for and not sure how to approach it.

I'm using wp_list_categories to obviously list terms of a taxonomy. I'd like to add some text to the end of each item.

Example being:

  • taxonomy_term some_new_text
  • instead of
  • taxonomy_term
  • Here's the basic wp_list_categories that I'm using:

    <?php 
        wp_list_categories(array( 
            'taxonomy' => 'locations',
            'orderby' => 'name',
            'style' => 'list',
            'order' => 'ASC',
            'title_li' => '',
            'number' => 25,
        ));
    ?>
    

    Thanks

    Final code used to accomplish what I need

    <?php
        $args = array(
            'taxonomy' => 'locations',
            'orderby' => 'name',
            'number' => 25,
        );
        $categories = get_categories( $args );
        foreach ( $categories as $category ) {
            echo '<li>&nbsp;<a href="/locations/' . $category->slug . '">' . $category->name . ' ' . get_the_title() . '</a> |&nbsp;</li>';
        }
    ?>
    
    share|improve this question

    2 Answers 2

    up vote 1 down vote accepted

    Use get_categories() (which returns an array of category objects rather than directly displaying them) instead of wp_list_categories, and loop through the results, outputting whatever you want.

    share|improve this answer
        
    Thanks! this worked great for what I needed. –  NW Tech May 13 '13 at 15:18

    You can also use a custom walker for wp_list_categories(). That is a custom class extending Walker_Category. In that class you can change anything, including the list item ends.

    Sample class

    class Extended_Walker_Category extends Walker_Category
    {
        function end_el( &$output, $page, $depth = 0, $args = array() ) {
            if ( 'list' != $args['style'] )
                return;
    
            $output .= " |&nbsp;</li>\n";
        }
    }
    

    Usage

    wp_list_categories(
        array (
            'taxonomy' => 'locations',
            'orderby'  => 'name',
            'style'    => 'list',
            'order'    => 'ASC',
            'title_li' => '',
            'number'   => 25,
            'walker'   => new Extended_Walker_Category
        )
    );
    
    share|improve this answer

    Your Answer

     
    discard

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

    Not the answer you're looking for? Browse other questions tagged or ask your own question.