知更鸟go.php,wordpress(知更鸟模板)实现文章阅读量的显示|时刻需

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); ?>

修改为如上所写。

在知更鸟的主题上 右上角的《编辑菜单》四个字去掉

不多说直接上图

1.png

这样就可以了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值