我试图每月只在查询中显示一篇帖子。
我可以将日期设置为变量,并使用php array_unique function 检查日期,只回显唯一的日期,但这感觉有点“骇客”。是否有内置的查询变量,或者我可以使用WordPress中的内置变量?
至于“hacky”选项,我对PHP还很陌生,正在努力使用前面提到的函数。检查日期是唯一的,只有当它已经在while循环中时才呼出所说的变量,这让我有些困惑。
下面是我当前使用的查询。
<?
$news_archive = array(
\'post_type\'=> \'news\',
\'posts_per_page\' => 6,
\'orderby\' => \'date\'
);
query_posts($news_archive);
echo \'<ul class="related_links">\';
while ( have_posts() ) : the_post();
$date = the_date(\'F m Y\',\'\',\'\',false);
$date = explode(\' \', $date);
$month_str = $date[0];
$month_int = $date[1];
$year = $date[2];
echo \'<li><a href="/archive/news/\' . $year . \'/\' . $month_int . \'/">\';
echo $month_str . \' \' . $year;
echo \'</a></li>\';
endwhile;
echo \'</ul>\';
endif;
wp_reset_query();
?>