这几天麦子在用WordPress仿站主题,在底部版权处一般我们会用到类似2020-2021这样的版权申明信息,这里我也不清楚为什么一定要这么做,反正看到大部分网站都是这么做的。那这里有一个问题,我们看到有些主题是固定的日期我们会每年修改一次,但是有些主题是动态的每年是会变后面的时间年份的。
那这个是如何实现的呢?
这里参考来自知更鸟博客的函数调用办法。
function zm_copyright() {
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'");
$output = '';
if( $copyright_dates ) {
$copyright = "© " . $copyright_dates[0]->firstdate;
if( $copyright_dates[0]->firstdate != $copyright_dates[0]->lastdate ) {
$copyright .= '-' . $copyright_dates[0]->lastdate;
}
$output = $copyright;
}
return $output;
}
将代码添加到当前的主题 Functions.php 中。然后我们在需要调用的页脚。插入代码。
<?php echo zm_copyright(); ?>
参考地址:https://zmingcx.com/wordpress-dynamic-copyright-date.html
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END