-
AuthorPosts
-
March 29, 2023 at 10:02 am #1402874
How to sort the displayed articles by popularity when clicking on a category or tag?
Most popular – first.March 29, 2023 at 11:11 am #1402877What expresses “popularity”? Comments or post views?
Do you measure your page views?March 29, 2023 at 1:48 pm #1402910Post views. We are using external counters, but it is difficult to use it with wortdpress core.
I found a code for resolving my problem, bit i’m not sure hoe to use it correctly with Enfold. May be you can help me?
To count the post views, the first thing you have to do is to add the following code to your WordPress Theme functions.php <?php /* * Set post views count using post meta//functions.php */ function customSetPostViews($postID) { $countKey = 'post_views_count'; $count = get_post_meta($postID, $countKey, true); if($count==''){ $count = 0; delete_post_meta($postID, $countKey); add_post_meta($postID, $countKey, '1'); }else{ $count++; update_post_meta($postID, $countKey, $count); } } ?> And now we will call this function in the single.php to update the count value in the Database. <?php customSetPostViews(get_the_ID());//single.php ?> Now to show all the popular post in the descending order by post view count. use this code: <?php//popular post query query_posts('meta_key=post_views_count&posts_per_page=5&orderby=meta_value_num& order=DESC'); if (have_posts()) : while (have_posts()) : the_post(); ?> <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li> <?php endwhile; endif; wp_reset_query(); ?>
April 1, 2023 at 5:35 pm #1403223Hi,
Thanks for sharing the code snippet but I don’t see a way to use this with the Enfold elements, I have opened a feature request for this option, but I’m not sure when it may be available, but I will reply back when I hear from the Dev Team, Thank you for your patience.Best regards,
MikeApril 1, 2023 at 9:05 pm #1403246but isn’t there already a count implemented in the combo widget?
So there must be a possibility to use that. Or is that a popularity used comment-count ?April 2, 2023 at 10:05 pm #1403333@Guenni007 What is combo widget? How to use it?
April 3, 2023 at 3:23 pm #1403415Hi,
Enfold Combo Widget is one of Enfold’s widgets. You can add it to your widget areas in Appearance > Widgets.
If you’d like to add it to your page, you can add a new widget area (https://i.imgur.com/zdPz3Vd.png), please Enfold Combo Widget inside it, edit the page where you’d like to display your widget, and add Widget Area element to your page to display it.
Best regards,
Yigit -
AuthorPosts
- You must be logged in to reply to this topic.