WordPress如何自动生成网站底部版权时间

WordPress如何自动生成网站底部版权时间

部分主题版权时间可能需要自己手动填写或者更改,今天给大家介绍一个可以自动生产网站底部版权时间的方法:

1、首先还是将自动生产版权的php函数添加到主题functions.php最后一个?php>

//自动生成版权时间
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;
}

2、在主题footer.php文件版权处适当位置加入显示时间的代码,一般添加在Copyright后,以flshow主题为例

Copyright <?php echo comicpress_copyright();?>

原文链接:https://88hzy.cn/1280.html,转载请注明出处。

0

评论0

请先

显示验证码
没有账号? 注册  忘记密码?