wordpress建站中,如何实现版权年份动态显示(自动变化年份),下面web建站小编给大家简单介绍一下!
找到主题下functions.php文件,新增以下代码:
复制代码function copyrightDate() {
global $wpdb;
$copyright_dates = $wpdb->get_results("
SELECT
YEAR(min(post_date_gmt)) AS firstdate,
YEAR(max(post_date_gmt)) AS lastdate
FROM
$wpdb->posts
WHERE post_status = 'publish'
");
if($copyright_dates) {
$date = date('Y-m-d');
$date = explode('-', $date);
$copyright = "Copyright © " . $copyright_dates[0]->firstdate;
if($copyright_dates[0]->firstdate != $date[0]) {
$copyright .= '-' . $date[0];
}
echo $copyright;
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
调用代码:
复制代码<?php copyrightDate();?>
- 1
wordpress建站如何快速提交和优化您的网站(IndexNow插件)?
标签: wordpress技巧, wordpress版权年份
上面是“wordpress如何实现版权年份动态显示”的全面内容,想了解更多关于 wordpress 内容,请继续关注web建站教程。
当前网址:https://m.ipkd.cn/webs_4706.html
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!