inove主题通过wp-postviews插件的方法设置在主页及文章页设置浏览次数需要
一、安装wp-postviews
登入网站后台—插件—安装插件—搜索wp-postviews即可
二、在首页显示的每篇文章的浏览次数
需要编辑的文件为主题目录下的index.php文件,所在的目录为/domains/liangzhaojun.com/public_html/wp-content/themes/inove/(此目录为用ftp连接到网站所在主机上的目录)。
打开index.php文件找到如下代码:
<?php if ($options[‘author’]) : ?><span class=”author”><?php the_author_posts_link(); ?></span><?php endif; ?>
<?php edit_post_link(__(‘Edit’, ‘inove’), ‘<span class=”editpost”>’, ‘</span>’); ?>
<span class=”comments”><?php comments_popup_link(__(‘No comments’, ‘inove’), __(‘1 comment’, ‘inove’), __(‘% comments’, ‘inove’), ”, __(‘Comments off’, ‘inove’)); ?></span>
在上面代码下面添加如下代码:
<span class=”comments”> <a href ><?php if(function_exists(‘the_views’)) { the_views(); } ?></a></span>
注意:其实下面需要修改文件添加的代码是相同的代码。
三、在具体的每篇文章中显示浏览次数
需要编辑的文件为主题下的single.php文件,所在的目录与index.php在相同的目录。
打开single.php文件找到如下代码:
<?php edit_post_link(__(‘Edit’, ‘inove’), ‘<span class=”editpost”>’, ‘</span>’); ?>
<?php if ($comments || comments_open()) : ?>
<span class=”addcomment”><a href=”#respond”><?php _e(‘Leave a comment’, ‘inove’); ?></a></span>
<span class=”comments”><a href=”#comments”><?php _e(‘Go to comments’, ‘inove’); ?></a></span>
在上面代码的下面添加如下代码:
<span class=”comments”> <a href ><?php if(function_exists(‘the_views’)) { the_views(); } ?></a></span>
四、在插件中设置显示的文字
进入网站后台—设置—PostViews找到Allowed Variables:- %VIEW_COUNT% 在后面的框中编辑要显示的文字即可,其中%VIEW_COUNT%味阅读次数的参数不要删掉。
附:如果需要在归档的文章中也显示浏览次数(我的博客是下拉列表的形式显示归档的所以没有体现出来浏览次数),需要修改主题目录下的archive.php 文件,与index.php、single.php在相同的目录。
打开archive.php文件找到如下代码:
<?php if ($options[‘author’]) : ?><span class=”author”><?php the_author_posts_link(); ?></span><?php endif; ?>
<?php edit_post_link(__(‘Edit’, ‘inove’), ‘<span class=”editpost”>’, ‘</span>’); ?>
<span class=”comments”><?php comments_popup_link(__(‘No comments’, ‘inove’), __(‘1 comment’, ‘inove’), __(‘% comments’, ‘inove’), ”, __(‘Comments off’, ‘inove’)); ?></span>
在上面代码的下面添加如下代码:
<span class=”comments”> <a href ><?php if(function_exists(‘the_views’)) { the_views(); } ?></a></span>
参考:
1、Edward’Blog http://www.edward-han.com/115.html
2、静风博客 http://www.jingfeng.info/archives/690.html