Forums

[resolved] How to count the number of posts per month (3 posts)

  1. rojaz
    Member
    Posted 3 years ago #

    Does anyone know how I could count the number of post per month. I looked and searched around, but I could not find anything. Thanks.

  2. MichaelH
    Volunteer
    Posted 3 years ago #

    Try:

    <?php
    $current_month = date('m');
    $current_year = date('Y');
    $countposts=get_posts("year=$current_year&monthnum=$current_month");
    echo 'the count of posts'  . count($countposts);
    ?>

    See:
    query_posts Time parameters
    get_posts()
    Stepping Into Template Tags
    Stepping Into Templates
    Template Hierarchy

  3. rojaz
    Member
    Posted 3 years ago #

    Thanks, but I figured it out another way. I was just creating an Archive page and I wanted to output the number of posts in each month. After reading some more source code & documentation, I found that all I had to do was add the argument "how_post_count=1" to the command "wp_get_archives('type=monthly')". If you or anyone else is curious, this is what i have now:

    <?php wp_get_archives('type=monthly&show_post_count=1'); ?>

    Thanks MichaelH.

Topic Closed

This topic has been closed to new replies.

About this Topic