Howto: WordPress: Agrupando posts por mês

Veja como fazer para puxar todos os posts de uma determinada categoria, exibindo em listas agrupadas por meses, assim:

Julho 2010

  • Titulo do post
  • Titulo do post

Junho 2010

  • Titulo do post
  • Titulo do post

Vejamos:

[sourcecode language=”php”]
< ?php $args=array( 'tag' => ‘tag1’,
‘posts_per_page’ => -1,
‘post_status’ => ‘publish’,
‘orderby’ => ‘date’,
‘order’ => ‘DESC’,
‘caller_get_posts’ =>1
);

$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
$ymdate = ”;
while ($my_query->have_posts()) : $my_query->the_post();
$ympost = mysql2date(“M Y”, $post->post_date);
if ( $ympost != $ymdate) {
$ymdate = $ympost;
echo ‘

Artigos do mes: ‘ . $ymdate . ‘

‘;
}
?>

< ?php the_time('F jS, Y') ?>


[/sourcecode]

[sourcecode language=”css”]

[/sourcecode]

[sourcecode language=”php”]

< ?php $args=array( 'cat' => ’12’,
‘posts_per_page’ => -1,
‘post_status’ => ‘publish’,
‘orderby’ => ‘date’,
‘order’ => ‘ASC’,
‘caller_get_posts’ =>1
);
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
$ymdate = ”;
while ($my_query->have_posts()) : $my_query->the_post();
$ympost = mysql2date(“F Y”, $post->post_date);
if ( $ympost != $ymdate) {
$ymdate = $ympost;
echo ‘

‘.$ymdate.’

‘;
echo ‘

‘;
} wp_reset_query();
?>
[/sourcecode]

Perfeito!!!

One thought on “Howto: WordPress: Agrupando posts por mês

Leave a Reply

Your email address will not be published. Required fields are marked *