درود
شما بدون افزونه هم میتونید این کارو بکنید روش کار به این صورته که
functions.php باز کنید و کد های زیر رو به اون اضافه کنید ( البته یادتون نره که از فانکشن خود یک کپی بگیرید منظور بکاپ هستش)
کد:<?php 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 "بدون بازدید"; } return $count.' بازدید'; } // function to 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()); ?><?php echo getPostViews(get_the_ID()); ?>





پاسخ با نقل قول