文章最后更新时间:
首先这个也是旧人花了点钱买的,我怕以后更新,忘了怎么搞所以发在资源网里。】
演示图
![图片[1]-子比主题 - 美化侧边栏添加网站统计小工具 - 旧人软件阁-旧人软件阁](https://img.y-9r.cn/uploads/2024/11/20241126172758358-47e217dfee2268a07aae88cc3e20f832.png)
教程简介
自定义PHP(放到function.php里)
//实现侧边栏文本工具运行PHP代码
add_filter('widget_text', 'php_text', 99);
function php_text($text) {
if (strpos($text, '<' . '?') !== false) {
ob_start();
eval('?' . '>' . $text);
$text = ob_get_contents();
ob_end_clean();
}
return $text;
}
function zfunc_comments_users($postid=0,$which=0) {
$comments = get_comments('status=approve&type=comment&post_id='.$postid); //获取文章的所有评论
if ($comments) {
$i=0; $j=0; $commentusers=array();
foreach ($comments as $comment) {
++$i;
if ($i==1) { $commentusers[] = $comment->comment_author_email; ++$j; }
if ( !in_array($comment->comment_author_email, $commentusers) ) {
$commentusers[] = $comment->comment_author_email;
++$j;
}
}
$output = array($j,$i);
$which = ($which == 0) ? 0 : 1;
return $output[$which]; //返回评论人数
}
return 0; //没有评论返回0
};
function nd_get_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;
}
自定义HTML(小工具的文本里)
<div class="textwidget"><p><script type="text/javascript">
function getRTime(){
var EndTime= new Date('2024/01/01 00:00:00'); //截止时间
var NowTime = new Date();
var t =EndTime.getTime() - NowTime.getTime();
var d=Math.floor(t/1000/60/60/24);
var h=Math.floor(t/1000/60/60%24);
var m=Math.floor(t/1000/60%60);
var s=Math.floor(t/1000%60);
document.getElementById("t_d").innerHTML = d + " 天";
document.getElementById("t_h").innerHTML = h + " 时";
document.getElementById("t_m").innerHTML = m + " 分";
document.getElementById("t_s").innerHTML = s + " 秒";
}
setInterval(getRTime,1000);
</script></p>
<div id="xypro">
<div class="text" style="text-align: center; font-weight: bold;">
<img style="border-top-left-radius: 8px; border-top-right-radius: 8px;" title="新年倒计时" alt="网站倒计时" data-src="https://huliku.com/images/tjty.gif" class="wp-smiley lazyloaded" src="https://huliku.com/images/tjty.gif" loading="lazy"><br>
<center><br>
<span style="color: #e80017;">2</span><span style="color: #d1002e;">0</span><span style="color: #ba0045;">2</span><span style="color: #a3005c;">4</span><span style="color: #8c0073;">年</span><span style="color: #75008a;"> – </span><span style="color: #5e00a1;">新</span><span style="color: #4700b8;">年</span><span style="color: #3000cf;">倒</span><span style="color: #1900e6;">计</span><span style="color: #0200fd;">时</span><br>
</center>
</div>
<div>
<div class="text" style="text-align: center; padding-bottom: 10px;">
<span id="t_d" style="font-weight: bold;"> 天</span> <span id="t_h" style="font-weight: bold;"> 时</span> <span id="t_m" style="font-weight: bold;"> 分</span> <span id="t_s" style="font-weight: bold;"> 秒</span>
</div>
<p></p></div>
<p></p></div>
<style>
.badge {
background-color: #814cff;
font-weight: 100;
}
</style>
<ul class="list-group box-shadow-wrap-normal">
<li class="list-group-item text-second">
<svg class="icon" aria-hidden="true"><use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#icon-chaxun"></use></svg> <span class="badge pull-right cursor" title="文章数目"><?php $count_posts = wp_count_posts(); echo $published_posts = $count_posts->publish;?>篇</span> 文章数目
</li>
<li class="list-group-item text-second">
<svg class="icon" aria-hidden="true"><use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#icon-yonghu"></use></svg> <span class="badge pull-right cursor" title="注册用户"><?php global $wpdb;$users = $wpdb->get_var("select count(id) from $wpdb->users");echo "$users" ?>位</span> 注册用户
</li>
<li class="list-group-item text-second">
<svg class="icon" aria-hidden="true"><use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#icon-rili1"></use></svg> <span class="badge pull-right cursor" title="运行天数"><?php echo floor((time()-strtotime("2022-09-23 13:57:00"))/86400); ?>天</span> 运行天数
</li>
<li class="list-group-item text-second">
<svg class="icon" aria-hidden="true"><use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#icon-xiaoxi1"></use></svg> <span class="badge pull-right cursor" title="评论数目"><?php { $num_comments = wp_count_comments(); echo $num_comments->total_comments; }?>条</span> 评论数目
</li>
<li class="list-group-item text-second">
<svg class="icon" aria-hidden="true"><use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#icon-fangke"></use></svg> <span class="badge pull-right cursor"><?php echo ''.nd_get_all_view().''; ?>次</span> 总访问量
</li>
</ul>
</div>
配置演示
![图片[2]-子比主题 - 美化侧边栏添加网站统计小工具 - 旧人软件阁-旧人软件阁](https://img.y-9r.cn/uploads/2024/11/20241126173145978-8e8c57a35bf933baee0c5a7e68fd4ac5.png)
PHP 代码只能在文本上输入,其他输入会出现错误现象
![图片[3]-子比主题 - 美化侧边栏添加网站统计小工具 - 旧人软件阁-旧人软件阁](https://img.y-9r.cn/uploads/2024/11/20241126173214478-0a8e3ee610ac481bcd9f27b6f2bb7b3f.png)
© 版权声明
© 版权声明 All Rights Reserved
THE END







暂无评论内容