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
Võ Minh Tốt (webseowp.vn)
Với hơn 4 năm kinh nghiệm lập trình (Python, PHP, JS, Wordpress...) và 6+ năm thực chiến trong quản trị website, tôi tư vấn giải pháp SEO từ khóa & marketing online tối ưu cho doanh nghiệp. Hiện là Trưởng phòng Kinh doanh tại Siêu Tốc Việt.