I want to display posts links from a category group by year. Group by year becouse by default wordpress repeat the date for each post. I try use a code but I got all post in current year. How can I do it? Example I want to do:
2010
- post link 20
- post link 19
- post link 18
- ...
- post link 8
2009
- post link 7
- post link 6
- ...
The code:
<?php
query_posts(array('nopaging' => 1, /* desabilitar a paginacao pata obter todos os pots. O padrao e ordenado pela data */));
$prev_year = null;
query_posts('cat=27');
if ( have_posts() ) {
while ( have_posts() ) {
$this_year = get_the_date('Y');
if ($prev_year != $this_year) {
// Year boundary
if (!is_null($prev_year)) {
// A list is already open, close it first
echo '</ul>';
}
echo '<h2 class="titulo-conteudo">'. $this_year . '</h2>';
echo '<div class="barra-amarela-4"></div>';
echo '<ul>';
}
echo '<li>';
// Imprimi o link do post.
the_post(); ?>
<div class="entry">
<h2 id="post-<?php the_ID(); ?>">
<a href="<?php the_permalink(the_title()) ?>"><?php the_title(); ?></a></h2>
</div>
<?php
echo '</li>';
$prev_year = $this_year;
}
echo '</ul>';
}
?>