In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces the method of displaying the article browsing statistics function without wordpress plug-in, the article is very detailed, has a certain reference value, interested friends must read it!
How to display article browsing statistics without the wordpress plug-in?
Wordpress no plug-in shows the number of views of the article, with a description of the principle, there are a lot of articles about this aspect on the Internet, but if you do not understand the principle of it, you will inevitably have some unease, for fear that the code will have any loopholes and affect the normal access of the website. Here's how it works. The code has been tested on wordpress 3.4.1.
Increase the number of views of the article
Wordpress itself does not have the statistical function of the number of page views of the article, so it is necessary to record the number of page views of the article before it can be read when the article is displayed. The text table in wordpress's database is wp_posts, in which there is no field of browsing times, which will be greatly changed if you add your own fields. A better way is to record the data in the wp_postmeta table, which is used to record some article extension data. The implementation code is as follows:
The code is as follows:
/ * set the number of times to browse the article * * @ param int $postID article number * / function setPostViews ($postID) {$count_key = 'post_views_count';$count = get_post_meta ($postID, $count_key, true); if ($count = =') {add_post_meta ($postID, $count_key,'1');} else {$count++;update_post_meta ($postID, $count_key, $count);}}
The process of the code is to first get the number of views of the article from wp_postmeta, and then judge: if not, increase the number of page views of the article, the initial value is set to 1; otherwise, the number of views will be increased by 1, and the number of article views will be updated.
Finally, just copy this code into the funtions.php file of the topic and call it in the main loop of the article page (single.php). The calling code is as follows:
The code is as follows:
Get the number of views of the article
The article can be read after browsing the record. The code is as follows:
The code is as follows:
Function getPostViews ($postID) {$count_key = 'post_views_count';$count = get_post_meta ($postID, $count_key, true); if ($count=='') {return 1;} return $count;}
The flow of the code is to get the number of views of the article from wp_postmeta, and return 1 if not, otherwise it will return the number of views.
Copy this code into the theme's funtions.php file and call this method where you need it.
The popular version on the Internet is to call delete_post_meta, and a closer look at the code shows that it is not necessary. There is also a postviews plug-in that can achieve similar functionality, but from the official website, it is only compatible with wordpress 3.3.2.
The above is all the contents of the method of displaying the article browsing statistics function without the wordpress plug-in, thank you for your reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.