我想按年份对帖子进行排序。以下代码几乎完美无缺。
但是当前年份(2017年)会多次显示,但其他年份只显示一次(应该如何)。我不明白这背后的逻辑。谢谢你的帮助!
的 2017
- 邮政6
的 2017
- 帖子5
的 2016
- 帖子4
- 邮政3
的 2015
- 邮政2
- 帖子1
*代码更新,但仍然是同样的问题。
<?php
$starting_year = date('Y');
$ending_year = 2010;
while ($starting_year > $ending_year):
$args = array( 'post_type' => 'ausstellungen', 'posts_per_page' => 99999, 'cat' => 6, 'year' => $starting_year );
$loop = new WP_Query( $args );?>
<?php while ( $loop->have_posts() ) : $loop->the_post();?>
<a class="lesetypo medium"><?php the_date('Y');?></a>
<li>
<?php while ($year =! $year): ?>
<div class="hide">
<?php $slug = $post->post_name;?>
<p><a href="<?php echo $slug ?>"><?php the_title();?></a></p>
</div>
<?php endwhile;?>
</li>
<?php endwhile;
$starting_year--;
endwhile;
?>
答案 0 :(得分:1)
您好,我已更新您的代码段,请仔细阅读以下代码
$starting_year = date('Y');
$ending_year = 2010;
while ($starting_year > $ending_year):
$args = array( 'post_type' => 'ausstellungen', 'posts_per_page' => 99999, 'cat' => 9, 'year' => $starting_year );
$loop = new WP_Query( $args );?>
<a class="lesetypo medium"><?php echo $starting_year;?></a>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<li>
<?php while ($year =! $year): ?>
<div class="hide">
<?php $slug = $post->post_name;?>
<p><a href="<?php echo $slug ?>"><?php the_title();?></a></p>
</div>
<?php endwhile;?>
</li>
<?php endwhile;
$starting_year--;
endwhile;