• I made a page with a tag list and I’d like to display the post count for each different tags.

    How do I do that?

    thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • <?php
    //list all tags that are assigned to posts
      $taxonomy = 'post_tag';
      $terms = get_terms( $taxonomy, '' );
      if ($terms) {
        foreach($terms as $term) {
          if ($term->count > 0) {
            echo '<p>' . '<a href="' . esc_attr(get_term_link($term, $taxonomy)) . '" title="' . sprintf( __( "View all posts in %s" ), $term->name ) . '" ' . '>' . $term->name.'</a> has ' . $term->count . ' post(s). </p> ';
          }
        }
      }
    ?>
    Thread Starter awhitemage

    (@awhitemage)

    I’ve found this, it’s more likely what I’m trying to do. But I can’t add PHP code to a page. Is there a better solution than installing the
    Exec-PHP plugin?

    <?php
    //assuming your tag id is 44
    $tags = get_tags('include=44');
    if ($tags) {
    foreach ($tags as $tag) {
    echo '<p>Tag: ' . $tag->name  . '(' . $tag->count . ')</p>';
    }
    }
    ?>

    Read the Pages article and review Page Templates.

    Related:
    Stepping Into Template Tags
    Stepping Into Templates
    Template Hierarchy

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Show posts count of tags?’ is closed to new replies.