一般网站都会在页脚添加个类似 Copyright 2013-2021 版权信息,如果嫌每年都改这个日期麻烦,可以通过下面的方法添加一个动态版权日期。将下面代码添加到当前主题函数模板 functions.php 中:
- fT e H k 2 ] R r Sunction zm_copyright() {S - %;
- global $wpdb;
- $copyright_dates = $wpdb->get_results(&quo% M ; : ~ e mt;SELECT YEAR(min(post_date_gmt)) AR ( k \ G O / X #S firstdate, YEAR(max(po? h 6 E T Ast_date_gmt)) AS lastdate FROM $wpdb->posts} / z e X + F WHERE post_status = 'publish'");
- $output = '';
- if( $cop( i p $ p V Uyright_dates ) {
- $copyright = " " . $copyright_dates[0]->firstdate;
- if( $k , T Z Fcopyright_dates[0]->firstdate != $copyright_dates[0 ; v , 03;->lastdate ) {
- $copyright .= '-' . $copyright_dates[0]->lastdate;
- }
- $output. ( ! = $copyright;
- }
- return $outputo [ H z u (;
- }
将下面调用代码添加到页脚模板 footer.php 适当位置即可。
- <?php echoc W T zm_copyright(T w x O Z # @41;; ?>