不想安装插件,所以想添加相关代码实现这个功能,但在网上找到的一个方法自己有些疑问,请教一下各位php达人和wordpress站长,谢谢了.
![](handshake.gif)

**功能实现很简单,为获得更合理的数据信息,添加了防刷新功能:

第一步:在主题functions.php文章加添加如下代码:

/*******************************
文章浏览计数器(显示文章浏览次数)
需要显示的位置添加:echo getPostViews(get_the_ID());

每篇文章的主循环加:setPostViews(get_the_ID());
**
********************************/
function getPostViews($postID){
$count_key = 'post_views_count';
$count = get_post_meta($postID, $count_key, true);
if($count==''){
delete_post_meta($postID, $count_key);
add_post_meta($postID, $count_key, '0');
return "0";
}
return $count;
}

function setPostViews($postID) {
$count_key = 'post_views_count';
$ViewedIDlist = $_COOKIE['ArticleIsViewed'];
$ViewidIsNull = False; //文章是否已阅读变量,为True时表示需要涮新阅读量
if(empty($ViewedIDlist)){
$ViewidIsNull = True;
}else{
$ViewidIsNull = True;
$ViewedIDarr = explode("[+]",$ViewedIDlist);
for($i=0; $iID); //添加文章浏览计数器;

第三步:在需要显示文章浏览次数的文件(如:single.php,home.php和)的显示位置添加代码:echo getPostViews($post->ID);。

红色标示的那行 **
每篇文章的主循环加:setPostViews(get_the_ID());
** 怎么理解呢?这行要在哪个文件中添加?谢谢了.