WordPress使用WP-PostViews实现网站上显示文章的浏览量

WordPress的使用很方便,但是文章的点击浏览量默认是没有的,本文介绍用WP-PostViews实现网站上显示文章的浏览量的功能。效果如下图所示:WP-PostViews_Settings

  • 安装WP-PostViews插件

在插件界面中安装WP-PostViews插件,并且启用插件。

  • 修改主题文件(Twenty Fourteen)

修改content.php,找到如下代码:

<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 -->

在后面添加:

<?php 
	/*View Counter for  wp-postviews*/
	if(function_exists('the_views')) { the_views(); } 
?>

修改后的结果如下:

<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,找到如下代码:

<footer class="entry-footer">
	<?php twentyfifteen_entry_meta(); ?>
	<?php edit_post_link( __( 'Edit', 'twentyfifteen' ), '<span class="edit-link">', '</span>' ); ?>
</footer><!-- .entry-footer -->

在后面添加:

<?php 
	/*View Counter for  wp-postviews*/
	if(function_exists('the_views')) { the_views(); } 
?>

修改后的结果如下:

<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 -->

发布者

《WordPress使用WP-PostViews实现网站上显示文章的浏览量》上有2条评论

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注