WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am having trouble figuring out a correct loop to display the following:

Category Name:

  • Post 1
  • Post 2
  • Post 3
  • Post 4
  • Post 5

See all posts in this category -->

Can anyone help me with a correct function or loop?

share|improve this question
For a single category or for all? – toscho Oct 26 '12 at 17:36
I think I want for all. So a page that would have a listing of categories like this. – Destructo Oct 26 '12 at 17:52
$categories = get_categories();
foreach($categories as $c) {
    echo '<h2>'. $c->name . '</h2>';
    $posts = get_posts(array( 'category' => $c->term_id, 'numberposts' => 5 ));
    foreach($posts as $post) {
        echo $post->post_title;
    <a href="<?php echo get_category_link($c->term_id);?>">
        View all posts in <?php echo $c->name;?>
share|improve this answer
Thank so much! That worked great. – Destructo Oct 29 '12 at 19:56

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.