- This topic has 1 reply, 2 voices, and was last updated 3 years, 8 months ago by
Leo.
-
AuthorPosts
-
July 19, 2022 at 3:57 pm #2287911
Ahmed
Hi there,
Wordpress Popular Posts is a plugin that shows popular posts in the last 1 day, week, month, etc. Unfortunately I find it hard to customize its CSS and I want to somehow show it with Generatepress. I’ve read about WP Show Posts but not sure how to pull this off.
They provide this code:
/** * Stores views of different time periods as meta keys. * * @author @migueleste / @radgh * @link https://wordpress.org/support/topic/how-to-sort-a-custom-query-by-views-all-time-monthly-weekly-or-daily/ * @param int $postid The ID of the current post/page/custom post type. */ function custom_wpp_update_postviews($postid) { // Accuracy: // 10 = 1 in 10 visits will update view count. (Recommended for high traffic sites.) // 30 = 30% of visits. (Medium traffic websites.) // 100 = Every visit. Creates many db write operations every request. $accuracy = 50; if ( function_exists('wpp_get_views') && (mt_rand(0,100) < $accuracy) ) { // Remove or comment out lines that you won't be using!! update_post_meta( $postid, 'views_total', wpp_get_views($postid, 'all', false) ); update_post_meta( $postid, 'views_daily', wpp_get_views($postid, 'daily', false) ); update_post_meta( $postid, 'views_weekly', wpp_get_views($postid, 'weekly', false) ); update_post_meta( $postid, 'views_monthly', wpp_get_views($postid, 'monthly', false) ); } } add_action('wpp_post_update_views', 'custom_wpp_update_postviews');You can find it here as well: https://wordpress.org/support/topic/how-to-sorting-a-custom-query-by-views-all-time-monthly-weekly-or-daily/
But I’m not sure if this can help with anything?
July 19, 2022 at 4:22 pm #2287918Leo
StaffCustomer SupportHi there,
WP Show Posts or the new Query Loop block from GenerateBlocks don’t include the logic to determine which posts are “popular”.
I would say that using the plugin + CSS is your best bet.
Otherwise you will need to create your own custom solution which is out of the scope of this forum.
You can try posting the question in a WordPress general forum like this one:
https://wordpress.stackexchange.com/Good luck!
-
AuthorPosts
- You must be logged in to reply to this topic.