کد در فایل فانکشن:
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); }}
کد در حلقه پست:
<?php setpostviews(get_the_ID()); ?>
نمایش تعداد بازدید هر پست:
[COLOR=#5A5A5A]<?php echo getpostviews(get_the_ID()); ?>[/COLOR]