Code hiển thị lượt xem bài viết wordpress
Thông có lẽ chúng ta sẽ plugin đếm số lượt view, bây giờ có khá là đa dạng plugin Giúp việc này, ở bài viết này chúng ta sẽ tiêu dùng code nhằm giảm thiểu bị đẩy mạnh tốc độ. các bạn copy đoạn code dưới đây và dán vào function nhéfunction setPostViews()$postID = get_the_ID();$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');hữu ích else$count++;update_post_meta($postID, $count_key, $count);xa
Sau đó chúng ta dùng hàm setPostViews(); dán nó vào bên trong khoảng lặp của bài viết tại file single.php của theme bạn đang tiêu dùng.

function getPostViews()$postID = get_the_ID(); $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"; chỉ return $count;

add_action( 'wp_enqueue_scripts', 'load_dashicons_front_end' ); function load_dashicons_front_end() wp_enqueue_style( 'dashicons' ); cần add_action('flatsome_blog_post_after','get_total_like'); function get_total_like();?> <div class="pt-view-cmt"> <div class="pt-cmt"> <span class="dashicons dashicons-admin-comments"></span> <span><?php echo get_comments_number();?></span> </div> <div class="pt-view"> <span class="dashicons dashicons-visibility"></span> <span><?php echo getPostViews(get_the_ID()); ?></span> </div> </div> <?php chính
Nguyễn Ngọc Kiên (sieutocviet.net)
Với hơn 6 năm phát triển web bằng WordPress, PHP, Laravel và kinh nghiệm quản trị website, tôi chuyên tư vấn SEO và chiến lược digital marketing cho doanh nghiệp vừa và lớn.