Forums

Listing categories with the post count included inside the link. (3 posts)

  1. Mercer2789
    Member
    Posted 2 years ago #

    Is it possible to make this:

    <li><a href="categories-url">categories name</a> (25)</li>

    into this:
    <li><a href="categories-url">categories name (25)</a></li>

  2. admark
    Member
    Posted 2 years ago #

    You could try something like this:

    <ul>
    <?php
    $args=array(
      'orderby' => 'name',
      'order' => 'ASC'
      );
    $categories=get_categories($args);
      foreach($categories as $category) {
        echo '<li><a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name. ' ('. $category->count . ')</a> </li> ';
    }
    ?>
    </ul>
  3. Mercer2789
    Member
    Posted 2 years ago #

    Works beautifully, thank you for the code. Any Idea how to list them in this format with parent category hierarchy? I'm assuming whatever I need to add to this for parent/child will be somewhere in the docs.

    Again, thank you, your help was very much appreciated.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.