今天换了个主题,顺便把浏览次数在文章下显示效果弄出来。
首先到插件里下载
然后启用该插件
1)Count Views From: 设置统计数据来源,可选项:所有人、仅访客、仅注册用户,默认:仅访客。
2)Exclude Bot Views: 是否排除搜索机器人(搜索引擎蜘蛛程序)的浏览数量,可选项:是、否,默认:否。
3)Views Template: 浏览数统计的显示模板,默认是:%VIEW_COUNT% views ,%VIEW_COUNT%变量表示浏览次数,views是固定显示文本。比如,默认会显示为“3 views”,我们可以更改其显示样式,如果要显示为“热度:3度”,我们可以将其改为“热度:%VIEW_COUNT%度”。
4)Most viewed Template: 网站Widget(微件)显示热门文章列表的模板。默认HTML格式是:<li><a href=”%POST_URL%” title=”%POST_TITLE%”>%POST_TITLE%</a> - %VIEW_COUNT% views</li>。其中,%POST_URL%是文章地址,%POST_TITLE%文章标题,%VIEW_COUNT%是浏览次数。我们可以更改成为自己想要的样式,比如个人博客的样式为:<li><a href=”%POST_URL%”>%POST_TITLE%</a><cite>(%VIEW_COUNT%)</cite></li>,完全根据自己需求来设置。
5)Display Options: 设置哪些页面可以显示浏览数统计,也可以指定给哪些人显示。其中,页面包括“Home page”主页、“single Posts”文章页、“Pages”页面、“Archive Pages”分类目录归档页、“Search Pages”搜索页、“Other Pages”其它页面,都可以独立配置。另个,每个配置下面都有三个选项可供选择:“Display to everyone”显示给所有人、“Display to registered users only”只显示给注册用户、“Don’t display on archive pages”不显示。
6)Uninstall WP-PostViews:WP-Postviews插件卸载。执行卸载后,WordPress Options/PostMetas数据表中的相关插件信息也将删除掉。
WP-Postviews插件使用方法:调用日志浏览统计
这是WP-Postviews插件的基本使用方法。如果想在你的主题上实现文章点击数,办法很简单,只需要在你的主题模板single.php或loop的相应位置加入以下代码即可:
<?php if(function_exists(‘the_views’)) { the_views(); } ?>
本人使用该方法:
cd /data/www/wwwroot/cenhq/wp-content/themes/travelify
vim library/structure/content-extensions.php
#修改一下内容,找到the_posts,在category后面添加代码,我列出的比较多。’…’为省略内容
function travelify_theloop_for_archive() {
global $post;
if( have_posts() ) {
while( have_posts() ) {
the_post();
do_action( ‘travelify_before_post’ );
?>
…
…
…
<div class=”entry-meta-bar clearfix”>
<div class=”entry-meta”>
<?php travelify_posted_on(); ?>
<?php if( has_category() ) { ?>
<span class=”category”><?php the_category(‘, ‘); ?></span>
<?php } ?>
<?php if ( comments_open() ) { ?>
<?php if(function_exists(‘the_views’)) { the_views(); } ?>
<span class=”comments”><?php comments_popup_link( ( ‘No Comments’, ‘travelify’ ), ( ‘1 Comment’, ‘travelify’ ), ( ‘% Comments’, ‘travelify’ ), ‘’, ( ‘Comments Off’, ‘travelify’ ) ); ?></span>
<?php } ?>
</div><!– .entry-meta –>
<?php
echo ‘<a class=”readmore” href=”‘ . get_permalink() . ‘“ title=”‘.the_title( ‘’, ‘’, false ).’”>’.( ‘Read more’, ‘travelify’ ).’</a>’;
?>
</div>
function travelify_theloop_for_single() {
global $post;
if( have_posts() ) {
while( have_posts() ) {
the_post();
do_action( ‘travelify_before_post’ );
?>
…
…
…
<div class=”entry-meta-bar clearfix”>
<div class=”entry-meta”>
<?php travelify_posted_on(); ?>
<?php if( has_category() ) { ?>
<span class=”category”><?php the_category(‘, ‘); ?></span>
<?php } ?>
<?php if(function_exists(‘the_views’)) { the_views(); } ?>
<?php if ( comments_open() ) { ?>
<span class=”comments”><?php comments_popup_link( ( ‘No Comments’, ‘travelify’ ), ( ‘1 Comment’, ‘travelify’ ), ( ‘% Comments’, ‘travelify’ ), ‘’, __( ‘Comments Off’, ‘travelify’ ) ); ?></span>
<?php } ?>
</div><!– .entry-meta –>
</div>
第一个函数修改完效果:

第二个函数修改完效果:
