邓先生的资源库

WordPress 添加动态版权日期

一般网站都会在页脚添加个类似Copyright ©2000-2021版权信息,如果嫌每年都改这个日期麻烦,可以通过下面的方法添加一个动态版权日期。

将下面代码添加到当前主题函数模板functions.php中:

function zm_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 zm_copyright(); ?>


本原创文章未经允许不得转载 | 当前页面:邓先生的资源库 » WordPress 添加动态版权日期

评论


|  Sitemap  |  App  |  Status  |  Stats  |  E-Mail |

已续  ,感谢有你
陕ICP备2022002237号

  开往-友链接力  飞翔