WordPress网站侧边栏一些常用的配置

配置日历和天气

定义的方式是 自定义HTML,如下图
file

具体的代码:

<iframe width="270" scrolling="no" height="90" style="margin-left: 0px" frameborder="0" allowtransparency="true" src="https://i.tianqi.com?c=code&id=7&icon=1&site=13"></iframe>

效果:
file

配置网站统计数据

配置方式为PHP代码,如下图:
file

建站天数: <?php
function diffDate($date1,$date2){
    $datetime1 = new DateTime($date1);
    $datetime2 = new DateTime($date2);
    $interval = $datetime1->diff($datetime2);
    $time['y']         = $interval->format('%y');
    $time['m']         = $interval->format('%m');
    $time['d']         = $interval->format('%d');
    $time['h']         = $interval->format('%H');
    $time['i']         = $interval->format('%i');
    $time['s']         = $interval->format('%s');
    $time['a']         = $interval->format('%a');    // 两个时间相差总天数
    return $time['y'].'年 '.$time['m'].'月 '.$time['d'].'天';
}

echo diffDate(date('Y-m-d H:i:s', time()), '2019-08-16 00:00:00');
?>

文章总数: <?php $count_posts = wp_count_posts(); echo $published_posts = $count_posts->publish;?> 篇

最后更新: <?php
function get_last_post_date(){
    global $wpdb;
    $last_post_date='';
    $last=$wpdb->get_var("select date_format(post_date, '%Y-%m-%d') from $wpdb->posts where post_type='post' and post_status='publish' order by post_date desc limit 1");

    return $last;
}

echo get_last_post_date();
?>

总浏览量: <?php
function get_all_post_view(){
    global $wpdb;
    $count=0;
    $views= $wpdb->get_results("SELECT t1.* FROM $wpdb->postmeta t1,$wpdb->posts t2  WHERE t1.meta_key='views' and t1.post_id=t2.id and t2.post_type='post'");
    foreach($views as $key=>$value){
        $meta_value=$value->meta_value;
        if($meta_value!=' '){
            $count+=(int)$meta_value;
        }
    }

    return $count;
}

echo number_format(get_all_post_view(),0,".",",");
?> 人次

总评论数: <?php $total_comments = get_comment_count(); echo $total_comments['approved'];?> 条

效果:
file

发布者:CoolQA,转转请注明出处:https://www.amwalle.com/more/working/20240330-wordpress%e7%bd%91%e7%ab%99%e4%be%a7%e8%be%b9%e6%a0%8f%e4%b8%80%e4%ba%9b%e5%b8%b8%e7%94%a8%e7%9a%84%e9%85%8d%e7%bd%ae.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
CoolQA的头像CoolQA
上一篇 2024年2月14日 20:38
下一篇 2023年7月16日 18:18

相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理