0

I am an editor of a blog with nearly 200 published articles that have been published within the last two years. All the popular posts plugins I've found show the most popular posts of all time. Understandably, the older posts have significantly more views because, well, they've been live for a lot longer than posts published in 2015.

I'm trying to figure out a way to display a number of posts in list form based on how many hits they received within the first 30 days of being published.

Any ideas as to where I should get started?

0

As Peter mentioned, Jetpack Stats would be a neat way to handle this. It has its own Popular Posts widget which you can take as a starting point, the API is fairly simple.

An alternative is the Google Analytics API. I wrote a tutorial about this quite a while ago, it's probably somewhat outdated, but it can be a good reference at what you should be looking for: http://theme.fm/2011/10/using-the-google-analytics-api-in-wordpress-2644/

Both approaches will allow you to limit the stats data to a certain date range.

And since you asked for "how many hits they received within the first 30 days of being published" I'll try and give some further thoughts.

I like that you're looking at the first 30 days and not the last 30 days. It'll give you a number that's probably much less affected by search engine rankings, etc. It's also a static number that once obtained, will never change, which means you can "cache" it forever.

But since each post can have a different publish date, it'll be pretty difficult to query stats for multiple posts at once, you'll most likely have to query them one by one.

I would run a background task that would look for posts older than 30 days, and ones that do not have our value cached yet. I would pick the first 50-100 such posts and query a stats API (Jetpack or Google Analytics) for each for the {published_date}-{published_date + 30 days} range and store the number of pageviews.

Running this task every hour or so will eventually fill out all your old posts, and you can then adjust the schedule to best suit your publishing intensity. And once you have this data, you can use it when querying your "popular" posts.

| improve this answer | |
0

You can try Jetpack by Wordpress Plugin

It can display list of most viewed posts in the sidebar of last 24 hours

Also it has detailed stats page

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.