久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      詳解WordPress文章閱讀量如何統(tǒng)計和顯示(非插件)

      下面由WordPress教程欄目給大家介紹WordPress文章閱讀量統(tǒng)計和顯示(非插件, 刷新頁面不累加),希望對需要的朋友有所幫助!

      WordPress文章閱讀量統(tǒng)計實現(xiàn)思路:

      每進入一次文章詳情頁面, 就會通過cookie判斷該用戶是否在設(shè)定的過期時間內(nèi)訪問過該文章, 若沒有訪問過, 則瀏覽次數(shù)增加一次。

      實現(xiàn)流程如下:

      1.添加以下代碼至主題的functions.php文件, 放在該文件最下面即可:

      function getPostViews($postID){     $count_key = 'views';     $count = get_post_meta($postID, $count_key, true);     if($count=='' || !$count){         return "0";     }     return $count; } function setPostViews($postID){     $count_key = 'views';     $count = get_post_meta($postID, $count_key, true);     if($count=='' || !$count) {         $count = 1;         delete_post_meta($postID, $count_key);         add_post_meta($postID, $count_key, $count);     }else{         $count++;         update_post_meta($postID, $count_key, $count);     } }

      2.添加以下代碼至主題的single.php 文件, 時間間隔可自定義設(shè)置, 放在該文件最上面即可:

      <?php  if(!isset($_COOKIE['views'.$post->ID.COOKIEHASH]) || $_COOKIE['views'.$post->ID.COOKIEHASH] != '1'){     setPostViews($post->ID);     setcookie('views'.$post->ID.COOKIEHASH,'1',time() + 99999999,COOKIEPATH,COOKIE_DOMAIN); }  ?>

      3.將以下代碼添加到要顯示瀏覽次數(shù)的位置, 例如 文章列表(template-parts/content.php), 文章詳情頁面(template-parts/content-single.php), 搜索結(jié)果頁面(template-parts/content-search.php)等。

      <?php echo getPostViews(get_the_ID());?>

      以下是我的個人博客 添加展示閱讀量的代碼和實際顯示效果。

      詳解WordPress文章閱讀量如何統(tǒng)計和顯示(非插件)

      贊(0)
      分享到: 更多 (0)
      網(wǎng)站地圖   滬ICP備18035694號-2    滬公網(wǎng)安備31011702889846號