2025年02月07日 建站教程
功能介绍:不想在首页/列表页显示最新的文章,需要显示指定时间内的文章。
解决方法如下:
在query_posts($query_string);
上面显示以下代码:
只显示<=前天发布的文章
if ( have_posts() ) { function filter_where($where = '') { $where .= " AND post_date <= '" . date('Y-m-d', strtotime('-1 days')) . "'"; return $where; } add_filter('posts_where', 'filter_where'); query_posts($query_string); ... ... }
显示30天内发布的文章
if ( have_posts() ) { function filter_where($where = '') { $where .= " AND post_date > '" . date('Y-m-d', strtotime('-30 days')) . "'"; return $where; } add_filter('posts_where', 'filter_where'); query_posts($query_string); ... ... }
只显示过去30天-60天内发布的文章
if ( have_posts() ) { function filter_where($where = '') { $where .= " AND post_date >= '" . date('Y-m-d', strtotime('-60 days')) . "'" . " AND post_date <= '" . date('Y-m-d', strtotime('-30 days')) . "'"; return $where; } add_filter('posts_where', 'filter_where'); query_posts($query_string); ... ... }
只显示某个时间段内发布的文章
if ( have_posts() ) { function filter_where($where = '') { $where .= " AND post_date >= '2022-03-01' AND post_date < '2023-03-01'"; return $where; } add_filter('posts_where', 'filter_where'); query_posts($query_string); ... ... }
本文链接:http://so.lmcjl.com/news/22717/