samedi 3 janvier 2015

Best approach to create Hot and Trending sections


I am going to implement a Hot and Trending section on a website. I have seen such sections on many popular websites but can't really figure out how exactly this works.


Although I assumed Hot section is most popular posts (based on post views) which I developed by a custom WP_Query. And it works.



$args = array(
'post_type' => 'post',
'post_status' => 'publish',
'meta_key' => 'post_views',
'orderby' => 'meta_value_num',
'ignore_sticky_posts' => 1,
'paged' => $paged,
);
$hot_query = new WP_Query( $args );


But I am stuck on Trending section. What exactly is the idea behind it for creating a custom query.


I want to know what is the best approach to get content in each section. I tried searching on Google for couple of days but could not really find anything useful.


EDIT


My post views function.



function set_post_views( $postID ) {
if ( is_singular() ) {
$count_key = 'post_views';
$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 );
}
}
}




Aucun commentaire:

Enregistrer un commentaire