Last active
April 8, 2019 07:03
-
-
Save naturallucky/d8253380975ad943a739eebf4b770883 to your computer and use it in GitHub Desktop.
WordPress Popular Posts all view custom
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="entry-views"> | |
<?php | |
if (function_exists('wpp_get_views')) { | |
//get each view number of page | |
$tcid = get_the_ID(); | |
$viewsArray = array( | |
wpp_get_views ( $tcid, 'dayly') | |
,wpp_get_views ( $tcid, 'weekly') | |
,wpp_get_views ( $tcid, 'monthly') | |
,wpp_get_views ( $tcid, 'all')); | |
$viewsArrayV = array( | |
wpp_get_views ( $tcid, 'dayly',false) | |
,wpp_get_views ( $tcid, 'weekly',false) | |
,wpp_get_views ( $tcid, 'monthly',false) | |
,wpp_get_views ( $tcid, 'all',false)); | |
//calc ratio of tendancy | |
$tdr = ((int)($viewsArrayV[0]*7000/$viewsArrayV[1]-1000)/10); | |
$tendancyDayly ="(".$tdr."%:".(($tdr>=30)?"↑":(($tdr<=-20)?"↓":"-")); | |
$twr = ((int)($viewsArrayV[1]*4000/$viewsArrayV[2]-1000)/10); | |
$tendancyWeekly="(".$twr."%:".(($twr>=30)?"↑":(($twr<=-20)?"↓":"-")); | |
//finally, print views info | |
echo '<span class="views" title="view: Daily: '.$viewsArray[0].$tendancyDayly | |
.') / Weekly: '.$viewsArray[1].$tendancyWeekly.') / Monthly: '.$viewsArray[2] | |
.' / All: '.$viewsArray[3].'">'.$viewsArray[3].' views.</span>'; | |
} | |
?> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
print page views of one article.
like "17,867 views." ( + mouse hover "view: Daily: 36(40%:↑) / Weekly: 180(-9.3%:-) / Monthly: 794 / All: 17,867")
require "WordPress Popular Posts" plugin.
write in:
wp-content/themes/(theme folder)/content-single.php
test under env:
wordpress 5.1.1 +WordPress Popular Posts 4.2.2 plugin. 2019/4/8
WordPress Popular Posts プラグイン利用した
ビュー数を表示する サンプルコード
総数の他に 増加・減少傾向も表示します。