Async's blog - 百度
type: channel
link: https://blog.async.website/index.php/tag/%E7%99%BE%E5%BA%A6/
items: 为Wordpress添加百度访客统计

为Wordpress添加百度访客统计
type: item
date: 2018-04-08T11:45:00+00:00
description: 0x00.在function.php中添加功能 //获取post_views function get_post_views ($post_id) { $count_key = 'views'; $count = get_post_meta($post_id, $count_key, true); if ($count == '') { delete_post_meta($post_id, $count_key); add_post_meta($post_id, $count_key, '0'); $count = '0'; } echo number_format_i18n($count); } //设置post_views function set_post_views () { global $post; $post_id = $post -> ID; $count_key = 'views'; $count = get_post_meta($post_id, $count_key, true); if (is_single() || is_page()) { if ($count == '') { delete_post_meta($post_id, $count_key); add_post_meta($post_id, $count_key, '0'); } else { update_post_meta($post_id, $count_key, $count + 1); } } } add_action('get_header', 'set_post_views');0x01.echo echo get_post_views(get_the_ID());即可输出访问次数。