Showing Recent and Lifetime Article Read Counts in WordPress Popular Posts

Add compact readership statistics to WordPress articles using WordPress Popular Posts. This tutorial combines comments, linked publication dates, rolling 12-month views, and total recorded reads into a clean metadata line, with responsive wrapping and copy-ready PHP that adapts to Twenty Twelve and other classic WordPress themes.

Contents

Introduction

If you use the WordPress Popular Posts plugin to track article views, you can expose those statistics directly in your WordPress theme.

On Horkan.com, I wanted each article to show something compact like this beneath the title:

No Comments · 07/09/2026 · 521 of 521 reads (last 12 months vs since 2024)

This gives the reader several useful pieces of information in one line: the comment count, publication date, readership during the rolling last 12 months, and total readership recorded since view tracking began.

This article shows how to implement it.

Why show two readership figures?

A lifetime view count is useful, but it naturally favours older articles. An article published ten years ago has had much longer to accumulate traffic than something published six months ago.

A rolling 12-month count provides another perspective: how much is the article actually being read now?

Displaying:

521 of 2,846 reads (last 12 months vs since 2024)

means that 521 of the 2,846 recorded reads occurred during the most recent 12 months.

I prefer a rolling 12-month figure to a calendar-year figure because it doesn’t reset on 1 January. It always represents the same length of time.

There is another reason for saying “since 2024” rather than “all time” in my case: that’s when I started collecting the statistics. Calling the figure “all time” would imply that it includes traffic from before tracking began.

WordPress Popular Posts and wpp_get_views()

The WordPress Popular Posts plugin provides the wpp_get_views() template tag, which allows a theme to retrieve the number of recorded views for a post.

For example:

$views_all_time = wpp_get_views(
    get_the_ID(),
    'all',
    true,
    true
);

The plugin also supports custom time ranges. That lets us retrieve views for the previous 12 months:

$views_12_months = wpp_get_views(
    get_the_ID(),
    array(
        'range'         => 'custom',
        'time_unit'     => 'month',
        'time_quantity' => 12
    ),
    true,
    true
);

The result is exactly what we need: one number representing recent readership and another representing everything recorded by the plugin.

Adding it to the WordPress post metadata

I’m using the classic Twenty Twelve theme, where the comments link is generated with comments_popup_link().

Rather than putting the readership statistics into a separate block, I wanted them to form part of the same article metadata.

Here is the complete code:

<?php if ( comments_open() ) : ?>

    <div class="comments-link">

        <?php
        /*
         * Comments
         */
        comments_popup_link(
            '<span class="leave-reply">' . __( 'Leave a reply', 'twentytwelve' ) . '</span>',
            __( '1 Reply', 'twentytwelve' ),
            __( '% Replies', 'twentytwelve' )
        );


        /*
         * Published date
         *
         * Day   -> daily archive
         * Month -> monthly archive
         * Year  -> yearly archive
         */
        $year  = get_the_date( 'Y' );
        $month = get_the_date( 'm' );
        $day   = get_the_date( 'd' );

        echo ' &middot; ';

        echo '<a href="' . esc_url( get_day_link( $year, $month, $day ) ) . '">'
            . esc_html( $day ) . '</a>/';

        echo '<a href="' . esc_url( get_month_link( $year, $month ) ) . '">'
            . esc_html( $month ) . '</a>/';

        echo '<a href="' . esc_url( get_year_link( $year ) ) . '">'
            . esc_html( $year ) . '</a>';


        /*
         * WordPress Popular Posts readership
         */
        if ( function_exists( 'wpp_get_views' ) ) {

            $post_id = get_the_ID();

            /*
             * Views during the rolling last 12 months
             */
            $views_12_months = wpp_get_views(
                $post_id,
                array(
                    'range'         => 'custom',
                    'time_unit'     => 'month',
                    'time_quantity' => 12
                ),
                true,
                true
            );

            /*
             * All views recorded by WordPress Popular Posts
             */
            $views_all_time = wpp_get_views(
                $post_id,
                'all',
                true,
                true
            );

            echo ' &middot; <span style="white-space: nowrap;">'
                . esc_html( $views_12_months )
                . ' of '
                . esc_html( $views_all_time )
                . ' reads (last 12 months vs since 2024)</span>';
        }
        ?>

    </div><!-- .comments-link -->

<?php endif; // comments_open() ?>

Making the date useful

There’s a small additional feature in the code that I particularly like.

Instead of making the publication date a single link, the day, month and year link independently to the corresponding WordPress archives.

For:

07/09/2026

07 links to the archive for 7 September 2026, 09 links to the September 2026 archive, and 2026 links to the archive for the whole year.

The relevant WordPress functions are:

get_day_link( $year, $month, $day );
get_month_link( $year, $month );
get_year_link( $year );

It turns an otherwise purely informational date into useful site navigation.

Keeping the readership statistic together

There is one small presentational problem with a metadata line like this.

At certain browser widths you can end up with something ugly like:

No Comments · 07/09/2026 · 521 of 521 reads (last 12
months vs since 2024)

I don’t want to prevent the entire metadata line from wrapping because that would cause problems on mobile devices.

Instead, only the readership statistic is prevented from wrapping:

<span style="white-space: nowrap;">

Consequently, the browser can display everything on one line when there’s enough room:

No Comments · 07/09/2026 · 521 of 521 reads (last 12 months vs since 2024)

But when there isn’t enough room, it can move the entire readership component onto the next line:

No Comments · 07/09/2026 ·
521 of 521 reads (last 12 months vs since 2024)

That’s much cleaner than allowing the explanatory text itself to break arbitrarily.

Adapting the code for your site

There are two things you’ll probably want to change.

First, change:

since 2024

to the year in which WordPress Popular Posts began recording your site’s views.

Second, the surrounding markup will depend on your theme. The example above is based on Twenty Twelve’s .comments-link structure, but the actual WPP portion is portable:

if ( function_exists( 'wpp_get_views' ) ) {

    $post_id = get_the_ID();

    $views_12_months = wpp_get_views(
        $post_id,
        array(
            'range'         => 'custom',
            'time_unit'     => 'month',
            'time_quantity' => 12
        ),
        true,
        true
    );

    $views_all_time = wpp_get_views(
        $post_id,
        'all',
        true,
        true
    );

    echo '<span style="white-space: nowrap;">'
        . esc_html( $views_12_months )
        . ' of '
        . esc_html( $views_all_time )
        . ' reads (last 12 months vs since 2024)</span>';
}

The function_exists() check is worth retaining. If WordPress Popular Posts is disabled or removed, the theme won’t try to call a function that no longer exists.

The result

The final metadata is intentionally compact:

No Comments · 07/09/2026 · 521 of 521 reads (last 12 months vs since 2024)

For an older article it becomes more informative:

3 Replies · 26/07/2023 · 1,247 of 5,832 reads (last 12 months vs since 2024)

That gives readers a quick indication not just of how much attention an article has accumulated, but whether people are still reading it now.

For an archive containing articles written over many years, I find that considerably more useful than a lifetime page-view counter on its own.

References