I use this function to set and get post view of post in my WordPress
function wpb_set_post_views($postID) {
$count_key = 'wpb_post_views_count';
$count = get_post_meta($postID, $count_key, true);
if($count==''){
$count = 0;
delete_post_meta($postID, $count_key);
add_post_meta($postID, $count_key, '0');
}else{
$count++;
update_post_meta($postID, $count_key, $count);
}
}
remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0);
function wpb_get_post_views($postID){
$count_key = 'wpb_post_views_count';
$count = get_post_meta($postID, $count_key, true);
if($count==''){
delete_post_meta($postID, $count_key);
add_post_meta($postID, $count_key, '0');
return "0 view";
}
return $count.' view';
}
Please , how can I check if an article is popular within a week or a month in archive list.
For example, if the article in list was popular during the same week, a .popular_week
class is added to the article.
like :
<div class="loop">
<div class="article">article1</div>
<div class="article">article2</div>
<div class="article popular_week">article3</div>
<div class="article">article4</div>
</div>
I hope the idea is clear