Wordpress 最后/最近一个月的员额
我有一份员工通讯,月刊就在它所指的月份之前出版 我需要我的索引页来显示最近一个月的帖子 例如: 当前月份是7月,但发布任何内容的最后一个月是5月,因此索引页面应该显示5月的帖子,直到下一组帖子发布 我使用的是:Wordpress 最后/最近一个月的员额,wordpress,posts,Wordpress,Posts,我有一份员工通讯,月刊就在它所指的月份之前出版 我需要我的索引页来显示最近一个月的帖子 例如: 当前月份是7月,但发布任何内容的最后一个月是5月,因此索引页面应该显示5月的帖子,直到下一组帖子发布 我使用的是: $current_month = date('m'); $current_year = date('Y'); query_posts("year=$current_year&monthnum=$current_month&order=DESC") 但这只会显示当月的帖子
$current_month = date('m');
$current_year = date('Y');
query_posts("year=$current_year&monthnum=$current_month&order=DESC")
但这只会显示当月的帖子,因此索引页现在为空,因为当月没有帖子
我有什么想法可以解决这个问题吗
谢谢使用此查询显示最近的上月帖子:
<?php
$today = getdate();
$args=array(
'post_type' => 'post',
'post_status' => 'publish',
'year'=>$today["year"],
'monthnum'=>$today["mon"]-1,
'order'=>'DESC',
'posts_per_page' =>10
);
query_posts($args);
?>
<?php while ( have_posts() ) : the_post(); ?>
<H1><?php echo the_title(); ?></H1>
<?php endwhile; ?>
使用此查询显示最近的上月帖子:
<?php
$today = getdate();
$args=array(
'post_type' => 'post',
'post_status' => 'publish',
'year'=>$today["year"],
'monthnum'=>$today["mon"]-1,
'order'=>'DESC',
'posts_per_page' =>10
);
query_posts($args);
?>
<?php while ( have_posts() ) : the_post(); ?>
<H1><?php echo the_title(); ?></H1>
<?php endwhile; ?>
明白了
$lastpost = strtotime(get_lastpostdate());
$lastmonth = date('m', $lastpost);
$lastyear = date('Y', $lastpost);
$args=array(
'post_type' => 'post',
'post_status' => 'publish',
'year'=>$lastyear,
'monthnum'=>$lastmonth,
'order'=>'DESC',
'posts_per_page' =>10
);
query_posts($args);
我将get_lastpostdate()转换为一个时间戳,并从该时间戳中获取年份和月份
$lastpost = strtotime(get_lastpostdate());
$lastmonth = date('m', $lastpost);
$lastyear = date('Y', $lastpost);
$args=array(
'post_type' => 'post',
'post_status' => 'publish',
'year'=>$lastyear,
'monthnum'=>$lastmonth,
'order'=>'DESC',
'posts_per_page' =>10
);
query_posts($args);
我将get_lastpostdate()转换为时间戳,并从该时间戳中获取年份和月份感谢您的输入,但这看起来是一种想法,它仅显示基于本月1的帖子。我需要显示基于上个月某个项目没有发布的帖子,不管它是在多久以前发布的。不是上个月,而是刚刚过去的那个月。谢谢,我确实考虑过最后一次约会。但是我不知道如何从这个函数中得到月份,因为抄本不是;在这个功能上不是很有帮助,或者它是一个有限的功能谢谢你的帮助-我找到了修复方法,你的回答很有帮助!谢谢你的意见,但它看起来是一个想法,这只显示了职位的基础上,这个月-1。我需要显示基于上个月某个项目没有发布的帖子,不管它是在多久以前发布的。不是上个月,而是刚刚过去的那个月。谢谢,我确实考虑过最后一次约会。但是我不知道如何从这个函数中得到月份,因为抄本不是;在这个功能上不是很有帮助,或者它是一个有限的功能谢谢你的帮助-我找到了修复方法,你的回答很有帮助!