wordpress本身不帶文章浏覽統計,可以用插件wp-postview,但是刷新還是算一個浏覽次數。
1.首先在主題下functions.php裡增加以下代碼,這段代碼也是網上可以找到的
getPostViews( = 'post_views_count' = get_post_meta(, , ( == '' delete_post_meta(, add_post_meta(, , '0' "0" setPostViews( = 'post_views_count' = get_post_meta(, , ( == '' = 0 delete_post_meta(, add_post_meta(, , '0' } ++ update_post_meta(, , }
2.解決刷新統計數增加,一定要放在文章頁面的最前面,貌似php設置cookie之前不能有輸出,蛋疼。我的是single.php頁面
<? = ((['views'..COOKIEHASH]) && ['views'..COOKIEHASH] == '1' setPostViews( ('views'..COOKIEHASH,'1',() + 3600,COOKIEPATH,COOKIE_DOMAIN); ?>