在functions.php下添加以下函数代码
//WordPress获取站点总浏览量
function all_view() /*注意这个函数名,调用的就是用它了*/
{
global $wpdb;
$count=0;
$views= $wpdb->get_results("SELECT * FROM $wpdb->postmeta WHERE meta_key='views'");
foreach($views as $key=>$value)
{
$meta_value=$value->meta_value;
if($meta_value!=' ')
{
$count+=(int)$meta_value;}
}
return $count;}
如需使用时可以放置以下语句
网站已运行:<span id="run_time" style="color: black;"></span>
<script>
function runTime() {
var d = new Date(), str = '';
BirthDay = new Date("20xx-xx-xx");
today = new Date();
timeold = (today.getTime() - BirthDay.getTime());
sectimeold = timeold / 1000
secondsold = Math.floor(sectimeold);
msPerDay = 24 * 60 * 60 * 1000
msPerYear = 365 * 24 * 60 * 60 * 1000
e_daysold = timeold / msPerDay
e_yearsold = timeold / msPerYear
daysold = Math.floor(e_daysold);
yearsold = Math.floor(e_yearsold);
//str = yearsold + "年";
str += daysold + "天";
str += d.getHours() + '时';
str += d.getMinutes() + '分';
str += d.getSeconds() + '秒';
return str;
}
setInterval(function () {
$('#run_time').html(runTime())
}, 1000);
</script>
其中“20xx-xx-xx”改为起始日期
网站已运行:
Comments | 1 条评论
博主 𝕐𝕚𝕤𝕙_
666