WordPress.org

Ready to get started?Download WordPress

Forums

wp_list_categories, show_count and taxonomy (9 posts)

  1. theshae
    Member
    Posted 3 years ago #

    Im using the below code to list terms in the genre taxonomy. I am also showing the post count and want to remove the ( ) around the numbers.
    So "(4)" will look like "4"
    Any ideas?

    <?php
    //list terms in a given taxonomy using wp_list_categories (also useful as a widget if using a PHP Code plugin)
    
    $taxonomy     = 'genre';
    $orderby      = 'name';
    $show_count   = 1;      // 1 for yes, 0 for no
    $pad_counts   = 0;      // 1 for yes, 0 for no
    $hierarchical = 1;      // 1 for yes, 0 for no
    $title        = '';
    
    $args = array(
      'taxonomy'     => $taxonomy,
      'orderby'      => $orderby,
      'show_count'   => $show_count,
      'pad_counts'   => $pad_counts,
      'hierarchical' => $hierarchical,
      'title_li'     => $title
    );
    ?>
    
    <ul>
    <?php wp_list_categories( $args ); ?>
    </ul>
  2. alchymyth
    The Sweeper & Moderator
    Posted 3 years ago #

  3. theshae
    Member
    Posted 3 years ago #

    I did, but it looks like it is handling taxonomy terms a little different.
    this works fo just categories:

    <?php
    $variable = wp_list_categories('echo=0&show_count=1&title_li=<h2>Categories</h2>');
    $variable = str_replace(array('(',')'), '', $variable);
    echo $variable;
    ?>

    but this wont work for the taxonomy terms:

    <?php
    //list terms in a given taxonomy using wp_list_categories (also useful as a widget if using a PHP Code plugin)
    
    $taxonomy     = 'jobtype';
    $orderby      = 'name';
    $show_count   = 1;      // 1 for yes, 0 for no
    $pad_counts   = 0;      // 1 for yes, 0 for no
    $hierarchical = 1;      // 1 for yes, 0 for no
    $title        = '';
    $empty        = 0;
    
    $args = array(
      'taxonomy'     => $taxonomy,
      'orderby'      => $orderby,
      'show_count'   => $show_count,
      'pad_counts'   => $pad_counts,
      'hierarchical' => $hierarchical,
      'title_li'     => $title,
      'hide_empty'   => $empty
    );
    ?>
    <ul data-role="listview">
    <?php $variable = wp_list_categories( $args );
    $variable = str_replace(array('(',')'), '', $variable);
    echo $variable; ?>
    </ul>

    I'm trying to wrap the show_count in:
    <span class="ui-li-count">12</span>

  4. alchymyth
    The Sweeper & Moderator
    Posted 3 years ago #

    but this wont work for the taxonomy terms:

    what is the result?

    you need to add the echo parameter into the $args:

    'echo' => 0,

    for the span, try:

    <?php $variable = wp_list_categories( $args );
    $variable = str_replace('(', '<span class="ui-li-count">', $variable);
    $variable = str_replace(')', '</span>', $variable);
    echo $variable; ?>

    (untested)

  5. theshae
    Member
    Posted 3 years ago #

    Ahh, worked perfect!

    Thanks alot alchymyth

    what does the 'echo' => 0, do?

  6. alchymyth
    The Sweeper & Moderator
    Posted 3 years ago #

    a:
    read it in the docu http://codex.wordpress.org/Template_Tags/wp_list_categories#Parameters;

    b:
    it controls if
    the list is going to be output to the screen (echo=1)
    or if the list is returned to be available as a string (echo=0)

  7. theshae
    Member
    Posted 3 years ago #

    I am taking in as much as I can and learning quickly!

    Thanks again.

  8. theshae
    Member
    Posted 3 years ago #

    How would I go about generating a list of terms from multiple taxonomies?

  9. Daniella
    Member
    Posted 3 years ago #

    I want to know that too!

Topic Closed

This topic has been closed to new replies.

About this Topic