wrodpress在页面上显示文章浏览量

原生的wordpress是没有浏览统计功能的,这个功能需要自己添加,个人觉得这是一个必备的功能,下面介绍如何添加此功能。

一、使用统计插件

本人使用的是WP-PostViews,这个插件属于必备插件之一,通过后台插件安装里搜索即可找到该插件,安装并启动

二、小工具使用

安装完插件后,你可以看到小工具中多了一个浏览排行的小工具,可以添加到侧边栏。

三、其他地方显示

仅仅在小工具中使用是远远不够的,我们还需要让所有文章都显示该文章的浏览量,这就需要使用一个调用功能,复制以下代码(此代码只有在插件安装完毕后才有效):

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

添加到你所需要显示的位置,这个你所需要的位置很尴尬,不同程序的模版不同,以本站为例,我需要在单页和首页文章标题下显示,所以我找到我index下的bolg-layout-1.php文件,这是我首页选择的布局,查找到下面代码:

<span class="entry-author"><a href="<?php echo get_author_posts_url( get_the_author_meta( 'ID' ), get_the_author_meta( 'user_nicename' ) ); ?>"><?php echo get_avatar( get_the_author_meta( 'ID' ), 48 ); ?></a> <?php esc_html_e('Posted by', 'vt-blogging'); ?> <?php the_author_posts_link(); ?></span> 
<span class="entry-date"><?php echo get_the_date(); ?></span>
<span class="entry-category"> <?php esc_html_e('In', 'vt-blogging'); ?> <?php vt_blogging_first_category(); ?></span> 

这个意思是显示作者头像,Posted by作者姓名,发布在哪个文章目录,而我们只需要用span标签填加到最后一行即可,完成后可显示,这样就实现在首页显示,同样,需要在单页中显示,找到single.php,下级的组件content-single.php文件,因为首页和文章页该代码是一样的,所以方法同上,保存后,单页也可以显示了。

对于完全没有学过PHP的我来说,现在是越来越清楚PHP建站的文件结构了

原创文章,转载请注明: 转载自飞月秀

本文链接地址: wrodpress在页面上显示文章浏览量

You May Also Like

About the Author: 楚有才

8 Comments

  1. I¡¦m not positive where you’re getting your info, but good topic. I needs to spend some time finding out more or working out more. Thank you for great information I used to be searching for this info for my mission.

  2. I would like to express some appreciation to the writer for rescuing me from this type of dilemma. Because of searching throughout the online world and getting ideas which are not powerful, I assumed my entire life was over. Being alive minus the solutions to the issues you’ve sorted out by way of your posting is a serious case, as well as ones which may have in a negative way damaged my career if I had not discovered your web page. The ability and kindness in maneuvering all the things was very useful. I don’t know what I would’ve done if I hadn’t encountered such a point like this. I am able to at this time relish my future. Thanks for your time very much for this impressive and sensible help. I won’t hesitate to suggest your web blog to any individual who needs to have care on this subject.

  3. I simply want to mention I am just new to blogs and absolutely enjoyed this page. Almost certainly I’m want to bookmark your website . You certainly come with fabulous posts. Thanks for sharing your webpage.

  4. “Hey! Would you mind if I share your blog with my facebook group? There’s a lot of folks that I think would really enjoy your content. Please let me know. Cheers”

  5. hHvrsN I truly appreciate this article post.Really looking forward to read more. Cool.

发表评论

电子邮件地址不会被公开。