自动生成copyright的时间

以下代码放进function.php

/*-----------------------------------------------------------------------------------*/
/* WordPress自动生成版权时间
/*-----------------------------------------------------------------------------------*/
function comicpress_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 comicpress_copyright(); ?>

以上原文来自:https://www.zlinet.com/11722.html

注意:从函数中的firstdate和lastdate的定义看,这个是根据发文的时间来确定版权时间的。