朱纯树博客
VPS测评推荐网站
cloudacead cloudacead

WordPress调用整站文章总浏览数量统计

最近本站官网改版,其中新版主题的底部有一个全站文章总浏览数量的浏览量统计效果,然后群里有个小伙伴问本站这个数据是怎么调用的,其实也挺简单的,在这里分享出来。

调用整站文章浏览数量的代码如下:

//WordPress全部文章总浏览数
function wpToo_all_view(){
	global $wpdb;
	$count=0;
	$views= $wpdb->get_results("SELECT * FROM $wpdb->postmeta WHERE meta_key='views'");
	foreach($views as $key=>$value){
		$meta_value=$value->meta_value;
		if($meta_value!=' '){
			$count+=(int)$meta_value;
		}
	}return $count;
}

使用方法

只需要将下面代码添加到正在使用主题的functions.php文件中,然后再需要显示全部文章总浏览数的地方加入下面代码即可

文章来源于互联网:WordPress调用整站文章总浏览数量统计

赞(0) 打赏
未经允许不得转载:VPS测评推荐网站 - 朱纯树博客 » WordPress调用整站文章总浏览数量统计

评论 13

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
  1. #0

    Thanks for sharing your thoughts about 杂七杂八.

    Regards

  2. #0

    I got this web page from my friend who informed me regarding this web
    page and now this time I am browsing this site and reading very informative articles
    or reviews at this place.

  3. #0

    I do not know if it’s just me or if perhaps everybody else
    encountering issues with your blog. It looks like some of the text
    within your content are running off the screen. Can somebody else please comment and let me know if
    this is happening to them too? This may be a problem with
    my browser because I’ve had this happen previously.
    Many thanks

  4. #0

    Oh my goodness! Impressive article dude! Thanks, However I am going through
    issues with your RSS. I don’t know why I am
    unable to join it. Is there anybody getting identical RSS
    issues? Anyone who knows the solution will you kindly respond?
    Thanx!!

    tinyurl.com1周前 (08-02)回复
  5. #0

    Hi there, I read your blog regularly. Your story-telling style is awesome, keep doing what you’re doing!

  6. #0

    I love what you guys tend to be up too. This sort of clever work and coverage!
    Keep up the terrific works guys I’ve included you guys to my own blogroll.

    bit.ly3个月前 (05-12)回复
  7. #0

    It is appropriate time to make some plans for the future and it’s time to be happy.

    I’ve read this post and if I could I want to suggest you few interesting things or suggestions.
    Maybe you can write next articles referring to this article.
    I want to read more things about it!

    gamefly4个月前 (04-07)回复
  8. #0

    Its such as you read my thoughts! You seem to grasp a lot approximately this,
    like you wrote the book in it or something. I feel that
    you just could do with some p.c. to pressure the message house a little bit, but instead of that, this is magnificent blog.
    A fantastic read. I’ll definitely be back.

  9. #0

    I’m not certain the place you’re getting your information, however good topic.
    I must spend some time finding out more or understanding more.
    Thanks for fantastic information I used to be on the lookout for this info for my
    mission.

  10. #0

    Very good post! We will be linking to this great article on our site.
    Keep up the good writing.

  11. #0

    I am sure this piece of writing has touched
    all the internet visitors, its really really pleasant post on building up new web
    site.

  12. #0

    Really when someone doesn’t understand after that its up to other
    users that they will assist, so here it takes place.

    tinyurl.com4个月前 (04-02)回复
  13. #0

    each time i used to read smaller articles or reviews that also clear their motive, and that is
    also happening with this piece of writing which I am reading now.