Feature Request: Add setting to exclude posts that have been on the most-viewed list for a certain duration
Is your feature request related to a problem? Please describe.
Would it be possible to add a setting to allow exclusion of posts that have appeared in the top lists for a certain amount of time?
Describe the solution you'd like
Some kind of option in the shortcode to use the WPP logs to track if a post has been in the top lists in a way that meets the plugin's current criteria and then give the user the option of not displaying it. For example, if I have a new "items of the week" article every week I might want to make them not display in the top posts lists after seven days but also not want to have to keep editing my shortcode to add more article IDs to exclude every week.
If post meets current settings X and post has met those criteria for period of time Z then don't display post for period of time Q.
Hi @grantbarrett,
Thanks for the suggestion! I got one better (?), how about for example adding new time range options, like:
- Current day
- Current week
- Current Month
That way your popular posts list will only pull data from eg. the current week, completely ignoring past data. That way, once the selected "current X" time range ends the next one will automatically only list items that are being viewed / commented on within the new time range. With this, you won't need to manually exclude IDs each week.
...hope I managed to explain myself, it makes sense in my head but it's Sunday night here and my brain is not in the freshest state right now haha 😅
That would be less processor-intensive, for sure! I think that would be an elegant solution to my situation.
Alright, I may create a separate branch to implement this functionality and ask you to test it out for me if that's OK. I'll let you know, no ETA though but hopefully soon.
Alright, took a little while but I just pushed a new branch called this-x-time-ranges that implements new time ranges as stated on this comment.
Branch: https://github.com/cabrerahector/wordpress-popular-posts/tree/feature/this-x-time-ranges PR: https://github.com/cabrerahector/wordpress-popular-posts/pull/395
Please give them a try and let me know if you have any comments/questions @grantbarrett
I will check it out!
Can you give guidance on how to test it with the shortcode? That's how I implement it. Thanks! @cabrerahector
Ah, forgot to mention that haha @grantbarrett
With this change, the range parameter now accepts the following values: today, thisweek and thismonth.
For example:
[wpp header='Popular Today' range='today']
[wpp header='Popular This Week' range='thisweek']
[wpp header='Popular This Month' range='thismonth']
As to how to get the actual plugin with these changes:
- Optional but highly recommended, create a full backup of your site (files and database.)
- Go to the time-x-ranges branch.
- Click on the green Code button near the top of the page.
- Click on the Download Zip button to download the plugin in .zip format and extract it into your desktop in its own folder (eg.
wordpress-popular-posts-feature-this-x-time-ranges). This is so there's no conflict with the regular WordPress Popular Posts plugin that's currently installed on your site. - Delete the zip file as it's no longer needed.
- Open
wordpress-popular-posts-feature-this-x-time-ranges\wordpress-popular-posts.phpwith a text editor (or a code editor if you use one) and changePlugin Name:to something likeWordPress Popular Posts, New Time Ranges Versionand save changes. - Delete the
wordpress-popular-posts-feature-this-x-time-ranges\uninstall.phpfile, this is so when you're done testing you can safely delete this dev version of the plugin without losing any popular posts data. - Create a new zip file from the
wordpress-popular-posts-feature-this-x-time-rangesfolder (or whatever you called it :P) - Go to your site > Plugins.
- Deactivate WordPress Popular Posts (do not uninstall it, just disable it.)
- Click on the Upload Plugin button at the top of the page, select the zip file you just created and follow the on-screen instructions to activate it.
Once you're done testing:
- Please share your feedback here.
- Disable and then delete the dev version of the plugin.
- Reactivate the regular WordPress Popular Posts plugin.
Thanks! That displays posts!
It is acting counter to expectations, however. I am using [wpp limit='6' range='thismonth' order_by='views' post_type='post' post_html='<li><a href="{url}" alt="{title_attr}" target="_blank">{title}</a></li>'] and it is showing posts from 2021 and 2012. They may have been updated this month (usually with things like tags) but they were first published long ago. I assume there is an internal modified date in WordPress the plugin is using that is not exposed in the dashboard; I would think it should use the published date that the WP control panel shows.
Also, can we get a thisyear in there? So many things are annual.
Yes, that shortcode will display the most viewed posts of this month regardless of their publication date.
If you want it to only list the most viewed posts that were also published within the current month use the freshness parameter (although that might need adjustment, I'm not sure if it'll work with the new time range options now that I think about it, I'll have a look at it later.)
[wpp limit='6' range='thismonth' freshness=1 order_by='views' post_type='post' post_html='<li><a href="{url}" alt="{title_attr}" target="_blank">{title}</a></li>']
Oh, see. I guess I kind of lost sight of what we were doing here. Sorry! I will look into freshness.
Don't worry about it, it's fine.
I'll look into adding a thisyear option, shouldn't be too much of an issue and I'm sure other people will want to have it too so it makes sense.
About some settings not being exposed on the Stats dashboard, someone already made a request to include them in #273 - I just keep forgetting about it (ᵕ・ᴗ・)
Since I haven't heard back from you @grantbarrett in a while I take it that the current-time-range feature is working as expected? :P
By the way, I just updated the feature/this-x-time-ranges branch to add the thisyear time range option as requested.
I'm thinking this looks ready to go as is but wanted to know if you had any further comments.
Sorry, I got distracted by other things, including Covid. I will try to look into this in the next couple of weeks.
Oh, so sorry to hear that. Hope you feel better!