WordPress主题中找到functions.php
,然后呢加入以下方法,代码如下:
//~ 历史上的今天,代码来自柳城博主的 WP-Today 插件 function today_in_history() { $title = "历史上的今天"; // 标题 $limit = 5; // 列表显示的数量,默认5条数据 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 $limit"; $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>$h_year: <a href='".$h_permalink."' title='查看: ".$h_post_title."'>$h_post_title <span>($h_comments 评)</span></a></li>"; } } if ( $h_post ){ $result = "<section class='history-in-today'><p><strong>".$title."</strong></p><div><ul>".$h_post."</ul></div></section>"; } else { $result = "<section class='history-in-today'><p><strong>".$title."</strong></p><div>很遗憾~,历史上的今天未发表过文章</div></section>"; } return $result; } 然后刷新就会看到效果了,如果曾经未发布过文章,会提示:“很遗憾~,历史上的今天未发表过文章”,反之则显示文章列表,样式自行调整吧!
At the beginning, I was still puzzled. Since I read your article, I have been very impressed. It has provided a lot of innovative ideas for my thesis related to gate.io. Thank u. But I still have some doubts, can you help me? Thanks.