最近访客
百度未收录

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

我们浏览一些网站经常能看到网页底部的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(); ?>

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

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

温馨提示: 本文最后更新于2022/10/20 13:20:05。若文章内容或图片失效,请 留言联系站长反馈!
!
也想出现在这里? 联系我们
创意广告
© 版权声明
THE END
点赞0赞赏 分享
评论 抢沙发

请登录后发表评论

    请登录后查看评论内容