code hiển thị lượt xem nội dung bài viết mới wordpress
Thông nắm tới lẽ chúng ta sẽ plugin đếm số lượt view, hiện nay sở hữu nhất khá là nhiều plugin giúp việc này, ở bài viết này chúng ta sẽ tiêu dùng lập trình nhất nhằm hạn chế bị tăng tốc độ. quý khách mới 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 tầm 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-người quản lý-comments"></span> <span><?php eđưa cho get_comments_number();?></span> </div> <div class="pt-view"> <span class="dashicons dashicons-visibility"></span> <span><?php eđưa cho getPostViews(get_the_ID());?></span> </div> </div> <?php chính
Nguyễn Văn Hải (hostmail.vn)
Với hơn 4 năm kinh nghiệm Drupal 8 năm kinh nghiệm trong quản lý web site tư vấn giải pháp đẩy top, Marketing tối ưu nhất cho công ty. Hiện giữ chức vụ quản lý kinh doanh tại Siêu Tốc Việt.