wordpress显示文章的阅读次数,WP-PostViews插件

[

这篇文章主要讲的是wordpress显示文章的阅读次数,WP-PostViews插件。 为了查找方便,小A汇总了所有wordpress的相关教程,方便大家查找到自己想要的wordpress教程:  wordpress教程汇总


wordpress显示文章的阅读次数,WP-PostViews插件 。我们知道,显示文章的阅读次数对SEO是有很大的好处的,因为每次点击都会对文章进行一次小小的更新,我们可以用下面的一款插件来实现这个功能:
WP-PostViews

1. 安装WP-PostViews插件


这个在安装插件里面安装即可。

2. 设置WP-PostViews插件


设置的路径是:设置——PostViews
首先,我们要把VPN设置成Count Views From: everyone,就是说每个人阅读一次,次数都会增加一次,如下:

wordpress显示文章的阅读次数,WP-PostViews插件
然后在display option那里也设置每个地方都能够展现次数:

wordpress显示文章的阅读次数,WP-PostViews插件

3. 在single.php对应的content-single.php的对应位置写上代码
展现文章次数的代码如下:


<?php if(function_exists('the_views')) { the_views(); } ?>

添加wordpress显示文章的阅读次数的代码如下,记得要添加进content-single.php里面:


<span> <i class="fa fa-eye"></i>

<a class="entry-author-link" rel="author" href="<?php echo esc_url( get_author_posts_url( get_the_author_meta( 'ID' ), get_the_author_meta( 'user_nicename' ) ) ); ?>">

<span class="entry-author-name">

<?php if(function_exists('the_views')) { the_views(); } ?>

</span>

</a>

</span>

下面我把content-single.php的代码写出来,大家可以参考一下,看看上面代码添加的位置:

</pre>

<?php /** * The template part for displaying single posts */ ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="entry-header">
<?php the_title( '
<h2 class="entry-title">', '</h2>

' ); ?>
</header>

<span>
<i class="fa fa-calendar"></i> <?php _e( 'Posted:', 'tannistha' ); ?>
<span class="posted-on">
<a href="<?php echo esc_url( get_day_link( get_the_date('Y'), get_the_date('m'), get_the_date('d') ) ); ?>">
<?php echo get_the_date('F d, Y'); ?>
</a>
</span>
</span>
<span class="entry-categories">
<i class="fa fa-th-list"></i> <?php _e( 'Under:', 'tannistha' ); ?>
<?php $tannistha_categories = get_the_category(); $tannistha_category_term_id = $tannistha_categories[0]->term_id;
if ( ! empty( $tannistha_category_term_id ) ) {
?>
<a rel="category tag" href="<?php echo esc_url( get_category_link( $tannistha_categories[0]->term_id ) ); ?>">
<?php echo esc_html( $tannistha_categories[0]->name ); ?>
</a>
<?php } ?>
</span>
<span>
<i class="fa fa-user"></i> <?php _e( 'By', 'tannistha' ); ?>
<span class="entry-author" >
<a class="entry-author-link" rel="author" href="<?php echo esc_url( get_author_posts_url( get_the_author_meta( 'ID' ), get_the_author_meta( 'user_nicename' ) ) ); ?>">
<span class="entry-author-name"><?php echo get_the_author(); ?></span>
</a>
</span>
</span>
<span>
<i class="fa fa-comments"></i>
<span class="entry-comments-link">
<a href="<?php echo esc_url( get_comments_link( get_the_ID() ) ); ?>"><?php comments_number( 'no Comments', '1 Comment', '% Comments' ); ?></a>
</span>
</span>

<span>
<i class="fa fa-eye"></i>
<a class="entry-author-link" rel="author" href="<?php echo esc_url( get_author_posts_url( get_the_author_meta( 'ID' ), get_the_author_meta( 'user_nicename' ) ) ); ?>">
<span class="entry-author-name"><?php if(function_exists('the_views')) { the_views(); } ?></span>
</a>
</span>
<div class="entry-content single-post-content">
<?php if ( has_post_thumbnail() ) { ?>
<figure class="wp-caption alignleft" >
<?php echo get_the_post_thumbnail(get_the_ID(), 'full'); ?>
</figure>

<?php } ?>
<?php the_content(); wp_link_pages( array( 'before' => '
<div class="page-links"><span class="page-links-title">' . __( 'Pages:', 'tannistha' ) . '</span>',
'after' => '</div>

',
'link_before' => '<span>',
'link_after' => '</span>',
'pagelink' => '<span class="screen-reader-text">' . __( 'Page', 'tannistha' ) . ' </span>%',
'separator' => '<span class="screen-reader-text">, </span>',
) );

if ( '' !== get_the_author_meta( 'description' ) ) {
get_template_part( 'template-parts/biography' );
}
?>
</div>
</article>
<pre>

4. CSS图标分类参考


我们看到了次数前面用的样式是fa fa-eye,添加了下面这个代码(这段代码也是展现文章次数的代码),使得文章阅读次数的开头有个眼睛的标志,那么,在这里我把所有图标CSS分类参考(点击这个链接)都给大家参考参考

<span>
 <i class="fa fa-eye"></i> 
 <a class="entry-author-link" rel="author" href="<?php echo esc_url( get_author_posts_url( get_the_author_meta( 'ID' ), get_the_author_meta( 'user_nicename' ) ) ); ?>">
 <span class="entry-author-name"><?php if(function_exists('the_views')) { the_views(); } ?></span>
 </a>
 </span>

本文内容来自:wordpress显示文章的阅读次数,WP-PostViews插件 - Break易站


—Author: Arvin Chen   —Web Address: www.breakyizhan.com (Break易站)

]
转载请保留页面地址:https://www.breakyizhan.com/wpress/627.html
原文地址:https://www.cnblogs.com/breakyizhan/p/13238257.html