久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放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. 站長(zhǎng)資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      wordpress查詢(xún)?yōu)g覽量需要用什么代碼

      wordpress查詢(xún)?yōu)g覽量需要用什么代碼

      用wordpress 搭建的博客或者企業(yè)站都有著同樣的需求,就是在內(nèi)容頁(yè)面需要統(tǒng)計(jì)這個(gè)頁(yè)面的瀏覽次數(shù),以方便站長(zhǎng)查看某個(gè)頁(yè)面的仿問(wèn)題,一般對(duì)代碼不熟悉的朋友都會(huì)用到瀏覽次數(shù)統(tǒng)計(jì)插件(WP-PostViews),但是眾所周知,一個(gè)站點(diǎn)如果插件安裝的多了會(huì)對(duì)SEO優(yōu)化 非常不利,那么下面給大家分享一個(gè)利用代碼來(lái)實(shí)現(xiàn)這種瀏覽次數(shù)的統(tǒng)計(jì)功能。

      1、在functions.php函數(shù)文件的未尾另起一行,添加如下代碼。

      <?php /* Postviews start */ 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';     $count = get_post_meta($postID, $count_key, true);     if($count==''){         $count = 0;         delete_post_meta($postID, $count_key);         add_post_meta($postID, $count_key, '0');     }else{        $count++;         update_post_meta($postID, $count_key, $count);     } } /* Postviews start end*/ ?>

      2、在您需要顯示統(tǒng)計(jì)瀏覽次數(shù)的頁(yè)面,例如在single.php內(nèi)容頁(yè)面中的<?php endwhile; ?>和<?php endif; wp_reset_query(); ?>循環(huán)語(yǔ)句的中間添加以下代碼:

      <?php setPostViews(get_the_ID());?>

      添加后的顯示,如:

       <?php endwhile; ?>      <?php setPostViews(get_the_ID());?> <?php endif; wp_reset_query(); ?>

      3、最后在您需要顯示統(tǒng)計(jì)的地方添加如下代碼:

      <?php echo getPostViews(get_the_ID()); ?> 次瀏覽

      更多wordpress相關(guān)技術(shù)文章,請(qǐng)?jiān)L問(wèn)wordpress教程欄目進(jìn)行學(xué)習(xí)!

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