Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Ex.

Category 1

Post 1

Post 2

Post 3

Post ....

Category 2

Post 1

Post 2

Post 3

Post ....

Category ....

Post 1

Post 2

Post 3

Post ....

share|improve this question

1 Answer 1

up vote 0 down vote accepted

Not sure if this is exactly what you're asking, but it sounds like you're looking for nested loops. This will list the most recent 5 posts in every category on your site:

foreach ( get_terms('category') as $category ) {

    echo '<h2>'.$category->name.'</h2>';
    echo '<ul>';

    foreach ( get_posts( 'cat='.$category->term_id ) as $post ) {
        setup_postdata( $post );
        echo '<li><a href="'.get_permalink($post->ID).'">'.get_the_title().'</a></li>';

    }
    echo '</ul>';
} 

Add the name of the custom post type and any other variables you may want to modify the loop with to the call to get_posts. You can look through the Codex page for a list of argument that can be passed.

share|improve this answer

Your Answer

 
discard

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