我能想到的最简单的方法就是这样。。。
<ul class="categories">
<?php
$categories = get_categories(); //can add parameters here to swtich the order, etc;
if(!empty(categories)):
foreach($categories as $i => $category):
?>
<li class="category">
<span><?php echo $category->name ?></span>
<?php
query_posts(\'posts_per_page=-1&cat=\' . $category->term_id);
if ( have_posts() ) :
?>
<ul class="posts">
<?php
while ( have_posts() ) : the_post(); //we make a loop for each category,
?>
<li class="post">
<a href="<?php the_permalink();?>"><?php the_title();?></a>
</li>
<?php endwhile; ?>
</ul>
<?php endif; ?>
<?php wp_reset_query(); ?>
</li>
<?php endforeach; endif; ?>
</ul>
警告:这是未经测试的代码,但应该可以正常工作。(只需将其添加到sidebar.php文件或生成侧栏的任何地方。)