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
Lê Trương Tấn Lộc (sieutocviet.page)
Có hơn 6 năm kinh nghiệm Laravel và 8 năm quản trị web site, tôi chuyên tư vấn đẩy top Google, Kinh doanh online tối ưu cho tập đoàn quốc tế, hiện làm giám đốc kinh doanh tại Siêu Tốc Việt.