php - Updating ID based on views -
currently have following block of code.
<?php $count = get_tptn_post_count_only($post_id); $rating_class = 'hot3'; if( $count >= 0 && $count <= 3 ) { $rating_class = 'hot3'; } elseif( $count > 4 && $count <= 10 ) { $rating_class = 'hot2'; } elseif( $count > 11 && $count <= 20 ) { $rating_class = 'hot1'; } elseif( $count > 5000 ) { $rating_class = 'hot1'; } ?>
now trying track views on post , if on number provided update image on index page accordingly how ever not seem work other hot3
portion first tier.
i basing of view tracking off of plugin called top 10. if you're interested in seeing entire loop can here.
edit: plugin settings.
also $totalcntaccess = get_tptn_post_count_only( $id, 'total', $blog_id );
inside of file counter.php <-- fiddle link.
found fix without using plugin above , using tool found on blog similar method.
functions.php (source)
function getpostviews($postid){ $count_key = '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.' views'; } function setpostviews($postid) { $count_key = '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 issues prefetching adding views remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0);
set in index of single.php file.
<?php setpostviews(get_the_id()); ?>
then on index loop make this.
<?php $count = getpostviews(get_the_id()); $rating_class = 'hot3'; if( $count >= 0 && $count <= 1000 ) { $rating_class = 'hot3'; } elseif( $count > 1000 && $count <= 2500 ) { $rating_class = 'hot2'; } elseif( $count > 2500 && $count <= 5000 ) { $rating_class = 'hot1'; } elseif( $count > 5000 ) { $rating_class = 'hot1'; } print $count; ?>
Comments
Post a Comment