老白瞎鼓捣系列:关闭WordPress文章浏览统计/发布时间功能-以document主题为例。网上有很多通过禁止disable_post_views_count查询的方式来关闭这个浏览,老白今天分享的是,从代码上直接删除相关部分。
[h2]1.删除文章浏览代码[/h2]
document主题文章的浏览数量关键词为“热度”,直接查找这个,看在哪些文件里面有即可
然后删除,比如下面这个文章信息模块,就有浏览量(热度)、评论、发布时间(time)和文章作者(author)
<div class="article-info">
<ul>
<li id="author"><i class="iconfont icon-chuangzuozhejieshao"></i><?php echo $author; ?></li>
<li id="category"><i class="iconfont icon-fenlei"></i><a href="<?php echo $link ?>"
title=" <?php echo $category; ?>"><?php echo $category; ?></a>
</li>
<li>
<i class="iconfont icon-shijian"></i><?php echo nicen_theme_timeToString( get_the_time( "Y-m-d H:i:s" ) ); ?>
</li>
<li><i class="iconfont icon-icon-test"></i><?php echo nicen_theme_getPostViews( get_the_ID() ); ?>热度</li>
<li style="border:none"><i class="iconfont icon-pinglun"></i><?php echo get_comments_number(); ?>评论</li>
</ul>
</div>
[h2]2.文章评论相关代码[/h2]
比如侧栏里面对于全站浏览数量和评论数量的统计,原来的代码需要查询,然后输出
/*
* 获取总浏览量
* */
$sql = 'select sum(`meta_value`+0) As views from `' . $table_prefix . 'postmeta` where `meta_key` = "post_views_count"';
$result = $wpdb->get_results($sql, ARRAY_A);
$views = $result[0]['views']; //总阅读数
$comment = count(get_comments());//评论总数
if ($count_posts) {
/* 已发布的数量 */
$publish = $count_posts->publish;
}
?>
<!--作者信息-->
<div class="author">
<div class="author-beijin">
<img src="<?php echo $beijin; ?>" title="作者头像"/>
</div>
<div class="offset">
<div class="author-avatar">
<img src="<?php echo $avatar; ?>" title="作者头像"/>
</div>
<div class="author-info">
<div class="nickname">
<?php echo $nickname; ?>
</div>
<div class="tag">
<?php echo $profession; ?>
</div>
</div>
<div class="author-self">
<?php echo $description; ?>
</div>
<div class="statistic">
<div class="item">
<span class="top">文章数</span>
<span class="bottom"><?php echo $publish; ?></span>
</div>
<div class="item">
<span class="top">评论数</span>
<span class="bottom"><?php echo $comment; ?></span>
</div>
<div class="item">
<span class="top">阅读数</span>
<span class="bottom"><?php echo $views; ?></span>
</div>
</div>
</div>
</div>
直接删除相关的浏览和评论查询,把数值固定
global $wpdb, $table_prefix; //数据库对象,表前缀
$count_posts = wp_count_posts(); //文章数量
$publish = 0; //已发布
if ($count_posts) {
$publish = $count_posts->publish;
}
?>
<!--作者信息-->
<div class="author">
<div class="author-beijin">
<img src="<?php echo $beijin; ?>" title="作者头像"/>
</div>
<div class="offset">
<div class="author-avatar">
<img src="<?php echo $avatar; ?>" title="作者头像"/>
</div>
<div class="author-info">
<div class="nickname">
<?php echo $nickname; ?>
</div>
<div class="tag">
<?php echo $profession; ?>
</div>
</div>
<div class="author-self">
<?php echo $description; ?>
</div>
<div class="statistic">
<div class="item">
<span class="top">文章数</span>
<span class="bottom"><?php echo $publish; ?></span>
</div>
<div class="item">
<span class="top">评论数</span>
<span class="bottom">固定值</span>
</div>
<div class="item">
<span class="top">阅读数</span>
<span class="bottom">固定值</span>
</div>
</div>
</div>
</div>
以上就是document主题的修改过程,对于其他主题也是类似的
本文作者为test,转载请注明。