WordPress –页脚中的动态版权日期
通常,您会发现版权日期已过时的网站。一些网站将当年作为其版权日期。两者都很烦人,这表明网站设计师是懒惰的。
为了向您的用户提供有关您网站的一些背景信息,您应该这样显示版权日期:©2006–2010。
我们可以通过简单地粘贴以下代码来做到这一点:
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;
}添加此功能后,打开footer.php文件,并在需要显示动态版权日期的任何地方添加以下代码:
此功能查找您的第一篇文章的日期和您的最后一篇文章的日期。然后,无论您在何处调用函数,它都会回显年份。