WordPress的使用很方便,但是文章的点击浏览量默认是没有的,本文介绍用WP-PostViews实现网站上显示文章的浏览量的功能。效果如下图所示:
- 安装WP-PostViews插件
在插件界面中安装WP-PostViews插件,并且启用插件。
- 修改主题文件(Twenty Fourteen)
修改content.php,找到如下代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
<div class="entry-meta"> <?php if ( 'post' == get_post_type() ) twentyfourteen_posted_on(); if ( ! post_password_required() && ( comments_open() || get_comments_number() ) ) : ?> <span class="comments-link"><?php comments_popup_link( __( 'Leave a comment', 'twentyfourteen' ), __( '1 Comment', 'twentyfourteen' ), __( '% Comments', 'twentyfourteen' ) ); ?></span> <?php endif; edit_post_link( __( 'Edit', 'twentyfourteen' ), '<span class="edit-link">', '</span>' ); ?> </div><!-- .entry-meta --> |
在后面添加:
1 2 3 4 |
<?php /*View Counter for wp-postviews*/ if(function_exists('the_views')) { the_views(); } ?> |
修改后的结果如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
<div class="entry-meta"> <?php if ( 'post' == get_post_type() ) twentyfourteen_posted_on(); if ( ! post_password_required() && ( comments_open() || get_comments_number() ) ) : ?> <span class="comments-link"><?php comments_popup_link( __( 'Leave a comment', 'twentyfourteen' ), __( '1 Comment', 'twentyfourteen' ), __( '% Comments', 'twentyfourteen' ) ); ?></span> <?php endif; edit_post_link( __( 'Edit', 'twentyfourteen' ), '<span class="edit-link">', '</span>' ); ?> <?php /*View Counter for wp-postviews*/ if(function_exists('the_views')) { the_views(); } ?> </div><!-- .entry-meta --> |
- 修改主题文件(Twenty Fifteen)
修改content.php,找到如下代码:
1 2 3 4 |
<footer class="entry-footer"> <?php twentyfifteen_entry_meta(); ?> <?php edit_post_link( __( 'Edit', 'twentyfifteen' ), '<span class="edit-link">', '</span>' ); ?> </footer><!-- .entry-footer --> |
在后面添加:
1 2 3 4 |
<?php /*View Counter for wp-postviews*/ if(function_exists('the_views')) { the_views(); } ?> |
修改后的结果如下:
1 2 3 4 5 6 7 8 |
<footer class="entry-footer"> <?php twentyfifteen_entry_meta(); ?> <?php edit_post_link( __( 'Edit', 'twentyfifteen' ), '<span class="edit-link">', '</span>' ); ?> <?php /*View Counter for wp-postviews*/ if(function_exists('the_views')) { the_views(); } ?> </footer><!-- .entry-footer --> |
请问这个插件如何屏蔽本地ip的访问,就是只显示别人的访问次数而不显示自己的?
如果没有设置的话,可以修改一下代码