WordPressで記事詳細ページのPV数を月別に表示したいのですが、
PV数を表示するやり方は検索で出てきたのですが、
これを月別または週別とかってできるのでしょうか?
検索でてこないとなるところをみると
出来ないということなのでしょうか?
①functions.phpに以下のコードを書く
php
1function getPostViews($postID){ 2$count_key = ‘post_views_count’; 3$count = get_post_meta($postID, $count_key, true); 4if($count==”){ 5delete_post_meta($postID, $count_key); 6add_post_meta($postID, $count_key, ‘0’); 7return “0 View”; 8} 9return $count.’ Views’; 10} 11function setPostViews($postID) { 12$count_key = ‘post_views_count’; 13$count = get_post_meta($postID, $count_key, true); 14if($count==”){ 15$count = 0; 16delete_post_meta($postID, $count_key); 17add_post_meta($postID, $count_key, ‘0’); 18}else{ 19$count++; 20update_post_meta($postID, $count_key, $count); 21} 22} 23remove_action( ‘wp_head’, ‘adjacent_posts_rel_link_wp_head’, 10, 0);
②表示させたい場所に以下のコードを書く
PHP
1<?php 2// views post metaで記事の情報を取得する 3setPostViews(get_the_ID()); 4echo getPostViews(get_the_ID()) ; 5?>
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/12/09 02:00