我想按年分类我的职位。下面的代码几乎可以完美地工作。但是当前年份(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;
?>发布于 2017-05-24 06:46:15
嗨,我已经更新了你的代码片段,请通过下面的代码
$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;https://stackoverflow.com/questions/44140468
复制相似问题