Lista de categoria com o último post de cada categoria no WordPress
Postado em 13 de maio de 2011 por Henderson | Categorias: Categorias | Tags: get_categories() | 1 Comentário » | Comentar
Para montar uma lista de categorias exibindo o resumo do último post de cada categoria use o código abaixo.
<?php $categories= get_categories(); $ic=1; foreach ($categories as $category) { $category = $category->cat_ID; query_posts("showposts=1&cat=$category"); ?> <?php while (have_posts()): the_post(); ?> <div style="margin-right: 12px;"> <h4><a href="<?php echo get_category_link($category);?>"><?php single_cat_title(); ?> »</a></h4> <div></div> <?php get_the_image( array( 'custom_key' => array( 'thumbnail' ), 'default_size' => 'thumbnail', 'width' => '140', 'height' => '140' ) ); ?> <h6><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title() ?></a></h6> <p style="color:#838383;"><?php the_time('d M, Y') ?></p> <p><?php echo substr(get_the_excerpt(),0,100)."(...)"; ?></p> </div> <?php //echo $ic; ?> <?php $ic=$ic+1; endwhile; ?> <?php } ?>
Referência do comando get_categories(): http://codex.wordpress.org/Function_Reference/get_categories