• Resolved further

    (@further)


    Hello!

    I’d like to get a post count on tags and categories once I open the archive page, next to the tag or category name.

    You can see an example of what i mean here:

    https://www.elblogalternativo.com/author/angel-de-la-guarda/
    (Los artículos de Angel de la Guarda (154):)

    I managed to get the category and tag name (single_cat_title and single_tag_title), but i’ve not found a tread dealing with this issue.

    Many thanks in advance!

    Erik.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Might be more than you need but try this in your archive.php:

    <?php
    $term_id='';
      if ( is_tag() ) {
        $term_id = get_query_var('tag_id');
        $taxonomy = 'post_tag';
        $title = 'Tag: ';
      }
      if ( is_category() ) {
        $term_id = get_query_var('cat');
        $taxonomy = 'category';
        $title = 'Category: ';
      }
    if ($term_id) {
      $args ='include=' . $term_id;
      $terms = get_terms( $taxonomy, $args );
      if ($terms) {
        foreach($terms as $term) {
          if ($term->count > 0) {
            echo '<p>' . $title . '<a href="' . get_term_link( $term->term_id, $taxonomy ) . '" title="' . sprintf( __( "View all posts in %s" ), $term->name ) . '" ' . '>' . $term->name.'</a> has ' . $term->count . ' post(s). </p> ';
          }
        }
      }
    }
    ?>
    Thread Starter further

    (@further)

    MichaelH, it works perfectly!

    I spent like 3 hours last week looking into the forums for a solution like this one and I found several other people with the same issue and no answer, you might wanna consider publishing it into the codex or something, it works fantastic!

    Many thanks,

    Erik.

    Eric – can you recommend a place in Codex to put that? Thanks.

    Agreed, that’s beautiful and rare.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Single Tag and Single Category count in Archive page’ is closed to new replies.