Ceci est similaire à la création d'un « Archive par catégorie la page » et peut être fait avec le code suivant:
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="post" id="post-<?php the_ID(); ?>">
<h2><?php the_title(); ?></h2>
<div class="entry">
<?php the_content('<p class="serif">Read the rest of this page »</p>'); ?>
<?php wp_link_pages(array('before' => '<p><strong>Pages:</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); ?>
</div>
</div>
<?php endwhile; endif; ?>
<!-- Category Archive Start -->
<ul class="catArchive">
<?php
$catQuery = $wpdb->get_results("SELECT * FROM $wpdb->terms AS wterms INNER JOIN $wpdb->term_taxonomy AS wtaxonomy ON (wterms.term_id = wtaxonomy.term_id) WHERE wtaxonomy.taxonomy = 'category' AND wtaxonomy.parent = 0 AND wtaxonomy.count > 0");
$catCounter = 0;
foreach ($catQuery as $category) {
$catCounter++;
$catStyle = '';
if (is_int($catCounter/2)) $catStyle = ' class="catAlt"';
$catLink = get_category_link($category->term_id);
echo '<li'.$catStyle.'><h3><a href="'.$catLink.'" title="'.$category->name.'">'.$category->name.'</a></h3>';
echo '<ul>';
query_posts('cat='.$category->term_id.'&showposts=5');?>
<?php while (have_posts()) : the_post(); ?>
<li><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; ?>
<li><a href="<?php echo $catLink; ?>" title="<?php echo $category->name; ?>">More <strong><?php echo $category->name; ?></strong></a></li>
</ul>
</li>
<?php } ?>
</ul>
<!-- Category Archive End -->
Notez que le code ci-dessus ne catégories d'affichage qui ont des postes qui leur sont associés, sinon ils sera sauté.
En outre, il ne diffuserons les 5 derniers messages de chaque catégorie. Vous pouvez changer cela en modifiant le nombre après la variable showposts. Par exemple, vous pouvez changer:
query_posts('cat='.$category->term_id.'&showposts=5');
à une situation où vous avez affiché 10 postes:
query_posts('cat='.$category->term_id.'&showposts=10');
Remplacez la ligne ci-dessus dans la boucle au début et vous devriez avoir un fonctionnement « Archive par catégorie "page.
double possible [les messages d'une catégorie dans Wordpress?] (Http://stackoverflow.com/questions/1735959/display-posts-from-a-category-in-wordpress) – Stephen