1.登录后台 外观=>编辑,然后找到function.php
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);
}
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');
将上边的代码写入function.php中
2.修改详情页 template/content.php
<?php if ( get_post_meta($post->ID, 'header_img', true) ) { ?>
<?php the_title( '
', '' ); ?>
<?php the_title( sprintf( '
', esc_url( get_permalink() ) ), '' ); ?>
阅读次数: <?php get_post_views($post -> ID); ?>
修改为如上所写。
在知更鸟的主题上 右上角的《编辑菜单》四个字去掉
不多说直接上图
这样就可以了