自动显示博客版权的方法

LMS
675 2

该方法可以动态地检查你的建博时间,若你的建博时间不满一年,则输出格式为:Copyright © 2009 Happyet.Org

若你的博客建立了超过一年的时间,则输出的格式为:Copyright © 2009-2010 Happyet.Org

在function.php文件中(好可怜,总是往这文件里塞东西!)复制添加下面代码:

function copyrightDate() {
        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
        ");
        if($copyright_dates) {
                $copyright = "Copyright © " . $copyright_dates[0]->firstdate;
                if($copyright_dates[0]->firstdate != $copyright_dates[0]->lastdate) {
                        $copyright .= '-' . $copyright_dates[0]->lastdate;
                }
                echo $copyright . " " . get_bloginfo('name');
        }
}
add_filter('wp_footer', 'copyrightDate');

就这样!

from:http://www.ihiro.org/4-ways-to-display-the-copyrights-of-blog

THE END

评论 2

  1. 万戈
    🏆🏅

    恩,用add_filter是最好的,可以防止采集

    1. add_fliter怎么防止采集

发表评论

Submit