[resolved] Counting how many posts are filed under one tag (3 posts)

  1. Nick
    Posted 8 years ago #


    On the archive page, I want to display how many posts are covered by the relevant category / tag archive.

    The following code shows the number of posts of a category:

    <div class="archive_number">
    This category contains <?php $cat = get_the_category(); $cat = $cat[0]; echo $cat->category_count; ?> posts

    Now, I want to display the number of posts filed under a tag. I've tried it with the following code:

    <div class="archive_number">
    <?php $tag = get_query_var('tag_id'); $tag = $tag[0]; echo $tag->tag_count; ?> posts are filed under this tag.

    But (of course) this does not work. Any ideas what I do wrong? Be patient, I'm a php n00b.

    Thanks for your help.

  2. Kafkaesqui

    Posted 8 years ago #

    Access it through the queried object on the page:

    $tag = $wp_query->get_queried_object();
    echo $tag->count;
  3. Nick
    Posted 8 years ago #



Topic Closed

This topic has been closed to new replies.

About this Topic