Displaying Top Pages

WP Statistics keeps track of every visit to your WordPress site. You can surface this data in a “Top Pages” list for your visitors—or just for yourself—using one of the two approaches below.

1. Use the Advanced Widgets Add‑on (No‑Code)

Best for site owners who prefer configuring through the WordPress admin UI.

  1. Install & activate the WP Statistics Advanced Widgets premium add‑on.
    • Download it from your WP Statistics account and install it like any other plugin.
    • Enter your license key under Statistics → Add-ons→ Install Add-ons.
  2. Add a widget or block.
    • Classic widgets: Go to Appearance → Widgets → drag the Statistics – Popular Posts widget into a sidebar or footer.
    • Gutenberg block: In the block editor, search for “WP Statistics – Popular Posts.”
  3. Configure options: Option What it does Date range Show visits from Today, Yesterday, Last 7 days, Custom, etc. Number of posts How many pages to list (default 5). Post type filter Limit results to posts, pages, products, etc. Display fields Toggle title, view count, thumbnail, excerpt.
  4. Save / update and preview your page. The list updates automatically as new visits are recorded.

2. Call wp_statistics_get_top_pages() in Your Theme / Plugin Code

Best for developers who need full control over markup or want to embed the list in custom templates.

Function Signature

array wp_statistics_get_top_pages(
    string|null $rangestartdate = null, // 'YYYY-MM-DD'
    string|null $rangeenddate   = null, // 'YYYY-MM-DD'
    int|null    $limit          = null, // max items (default 5)
    string|array|null $post_type = null // 'post', 'page', ['post','product'], etc.
)

Returns an array of rows, one per page:

[
  [0] => uri (string)         // e.g. '/about-us/'
  [1] => views (int)          // total or range‑limited count
  [2] => page_id (int)        // WordPress post ID
  [3] => title (string)       // up to 200 chars
  [4] => url (string)         // absolute permalink
]

Quick Parameter Reference

ParameterRequiredDescription
$rangestartdateNoStart of the period to analyse (inclusive). Use null for “all‑time.”
$rangeenddateNoEnd of the period (inclusive). Must be supplied if you pass a start date.
$limitNoMaximum number of pages to return. Defaults to 5.
$post_typeNoA single post type ('post') or an array (['post','product']). null = all types.

Minimal Example

// Show this month’s 10 most‑viewed blog posts
$top_posts = wp_statistics_get_top_pages(
    date('Y-m-01'),          // first day of current month
    date('Y-m-d'),           // today
    10,                      // limit
    'post'                   // post type
);

if ( $top_posts[1] ) {
    echo '<ol class="top-posts">';
    foreach ( $top_posts[1] as $page ) {
        [$uri, $views, $id, $title, $link] = $page;
        printf('<li><a href="%s">%s</a> <span class="views">%d views</span></li>',
               esc_url($link), esc_html($title), $views);
    }
    echo '</ol>';
}

Tips & Gotchas

Let’s get started
Take your business to next level

Become part of our growing family of +600,000 users and get the tools you need to make smart choices for your website. Simple, powerful insights are just a click away.