AIDE技术官网
AIDEZY.COM

WordPress代码实现文章下显示历史上的今天功能

WordPress代码实现文章下显示历史上的今天功能

WordPress代码实现文章下显示历史上的今天功能

前言:

WordPress代码实现文章下显示历史的今天功能,如果有帮助就看看吧。

WordPress代码实现文章下显示历史上的今天功能|正文

 

正文:

WordPress代实现章下示历史上的今天功能,码只对建站一年以的有用,这里顺便了一下柳城的件,传启用就以实现了,用代的话把下面代码丢到主题函文件(functions.php)即可在文下方显示,注只有以前同一发过文章才能示,不然留空

//历史上的今天,代码来自柳城博主的WP-Today插件

function wp_today(){

    global $wpdb;

    $post_year = get_the_time('Y');

    $post_month = get_the_time('m');

    $post_day = get_the_time('j');

    $sql = "select ID, year(post_date_gmt) as h_year, post_title, comment_count FROM 

            $wpdb->posts WHERE post_password = '' AND post_type = 'post' AND post_status = 'publish'

            AND year(post_date_gmt)!='$post_year' AND month(post_date_gmt)='$post_month' AND day(post_date_gmt)='$post_day'

            order by post_date_gmt DESC limit 5";

    $histtory_post = $wpdb->get_results($sql);

    if$histtory_post ){

        foreach$histtory_post as $post ){

            $h_year = $post->h_year;

            $h_post_title = $post->post_title;

            $h_permalink = get_permalink( $post->ID );

            $h_comments = $post->comment_count;

            $h_post .= "<li><strong>$h_year:</strong>&nbsp;&nbsp;<a href='".$h_permalink."' title='".$h_post_title."' target='_blank'>$h_post_title($h_comments)</a></li>";

        }

    }

    if ( $h_post ){

        $result = "<h2>历史上的今天:</h2><ul>".$h_post."</ul>";

    }

    return $result;

}

function wp_today_auto($content){

    if( is_single() ){

        $content = $content.wp_today();

    }

    return $content;

}

add_filter('the_content', 'wp_today_auto',9999);

 

海报生成 赞(1) 打赏

来都来了!评论一下呗! 抢沙发

  • QQ (自动获取名称头像等信息|选填)
  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址 (选填)

登录

忘记密码 ?

切换登录

注册