====================================================
Howto: Como gerar um menu agrupando as postagem por ano e mês
====================================================
A idéia é fazer um menu assim:
2009
- Maio
- Abril
- Março
- Fevereiro
- Janeiro
2008
- Dezembro
- Novembro
O código é simples:
<ul>
<?php
/**/
$years = $wpdb->get_col("SELECT DISTINCT YEAR(post_date)
FROM $wpdb->posts WHERE post_status = "publish"
AND post_type = "post" ORDER BY post_date DESC");
foreach($years as $year) :
?>
<li><a href="<?php echo get_year_link($year); ?> ">
<?php echo $year; ?></a>
<ul>
<? $months = $wpdb->get_col("SELECT DISTINCT MONTH(post_date)
FROM $wpdb->posts WHERE post_status = "publish"
AND post_type = "post" AND YEAR(post_date) = "".$year.""
ORDER BY post_date DESC");
foreach($months as $month) :
?>
<li><a href="<?php echo get_month_link($year, $month); ?>">
<?php echo date( "F", mktime(0, 0, 0, $month) );?></a></li>
<?php endforeach;?>
</ul>
</li>
<?php endforeach; ?>
</ul>
Veja também...
- Exec-PHP – Executar códigos PHP direto na edição de posts e pages no WordPress
- Integrando o SlideShowPro ao WordPress
- Best Practice: Select lentas, rápidas e super-rápidas.
- Resultado de dois bancos distintos em apenas um SQL
- Comparando valores Boolean no Postgresql
Related posts brought to you by Yet Another Related Posts Plugin.
