wordpressのthe_date()はあるけど、the_year()というのはないので下記のソースで対応。
<?php $year_check = ''; ?> <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <?php $year = get_the_date('Y'); if($year_check !='' && $year != $year_check){ echo '</ul>' ; } if( $year != $year_check){ echo '<h3>' . $year . '</h3>'; echo ' <ul>'; } $year_check = $year; ?> <li> <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> </li> <?php endwhile; endif; ?>
HTML出力
<h3>2014</h3> <ul> <li><a href="#">記事のタイトル4</a></li> <li><a href="#">記事のタイトル3</a></li> <li><a href="#">記事のタイトル2</a></li> </ul> <h3>2013</h3> <ul> <li><a href="#">記事のタイトル1</a></li> </ul>
参考サイト
wordpress – How can I display post link group by year?