2232588429
V2EX  ›  问与答

WP 文章阅读数统计代码没有排除本地 IP,请问这个问题在哪?该如何修改?

  •  
  •   2232588429 · Dec 24, 2014 · 2286 views
    This topic created in 4183 days ago, the information mentioned may be changed or developed.

    贴一下原阅读数量统计代码,请V友帮忙解惑一下谢谢!

    function record_visitors()
    {
    if (is_singular())
    {
    global $post;
    $post_ID = $post->ID;
    if($post_ID)
    {
    $post_views = (int)get_post_meta($post_ID, 'views', true);
    if(!update_post_meta($post_ID, 'views', ($post_views+1)))
    {
    add_post_meta($post_ID, 'views', 1, true);
    }
    }
    }
    }
    add_action('wp_head', 'record_visitors');

    function post_views($before = '(点击 ', $after = ' 次)', $echo = 1)
    {
    global $post;
    $post_ID = $post->ID;
    $views = (int)get_post_meta($post_ID, 'views', true);
    if ($echo) echo $before, number_format($views), $after;
    else return $views;
    }

    1 replies    2014-12-24 12:49:54 +08:00
    iwillhappy1314
        1
    iwillhappy1314  
       Dec 24, 2014   ❤️ 1
    判断一下,如果是已登陆用户,不运行代码就可以了。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2963 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 14:43 · PVG 22:43 · LAX 07:43 · JFK 10:43
    ♥ Do have faith in what you're doing.