WordPress网站底部自动生成copyright版权起止时间

我们浏览一些网站经常能看到网页底部的copyright信息,如本站网页下方显示的建站年份到目前年份的信息。

WordPress网站底部自动生成copyright版权起止时间

那么,如何能自动获取网站的建站时间,生成上图显示的效果呢?其实也很简单,把下方的代码放进当前主题的functions.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;
}

然后在页脚 footer.php 模板文件的合适位置(小编以前用dux主题,是在第40行添加的),加入以下代码就行了!

<?php echo comicpress_copyright(); ?>

然后,刷新网页看看效果吧!

注意:修改网站模板前,务必备份好网站数据。这样万一修改出现问题,方便恢复网站内容。

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

给TA打赏
共{{data.count}}人
人已打赏
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索