2024年05月30日 建站教程
每个网站底部都会出现一个版权日期,比如web建站建站的版权日期是Copyright©2019-2023,那么如何实现每年自动更新呢?
function ipkd_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;
}
在页面中调用一以下代码:
<?php echo ipkd_copyright(); ?>
本文链接:http://so.lmcjl.com/news/5593/