我想僅在當前月份的wordpress中顯示特定類別中的所有帖子。意味着它將僅顯示當前月份的此類別中的所有帖子,然後分別顯示上個月和下個月的分頁。在wordpress中按月顯示帖子
問題更新 我試過這段代碼。 這是按月顯示帖子,但需要一種方法來顯示此只爲當前月份,然後分頁爲上個月。
<?php
$blogtime = date('Y');
$prev_limit_year = $blogtime - 1;
$prev_month = '';
$prev_year = '';
$args = array(
'posts_per_page' => 20,
'ignore_sticky_posts' => 1,
'cat' => 1
);
$postsbymonth = new WP_Query($args);
while($postsbymonth->have_posts()) {
$postsbymonth->the_post();
if(get_the_time('F') != $prev_month || get_the_time('Y') != $prev_year && get_the_time('Y') == $prev_limit_year) {
echo "<h2>".get_the_time('F, Y')."</h2>\n\n";
}
?>
<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
<?php // your other template tags ?>
<?php
$prev_month = get_the_time('F');
$prev_year = get_the_time('Y');
}
?>
@Christophvh我已經添加代碼。 –