プレミアムWPテーマプラグイン 無料ダウンロード

Reply To:bbpressで作られた掲示板です

質問の送信 > 全てのフォーラム > Reply To:bbpressで作られた掲示板です

文のカウンタ関数

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 View";
    }
    return $count.' Views';
}
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);
    }
}

// Remove issues with prefetching adding extra views
remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0);

適用:
<?php setPostViews(get_the_ID()); ?>

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