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.

What I want to do is a loop like this is something like this I'm really sorry but its hard to format here!

I going to put this short url http://pastebin.com/dEdKzgJz so you can see it better... Can anyone help me with this? Any advice!

Category 1
........Child Category 1.1
...........Sub-Child Category 1.1.1
.................Post Title 1
.................Post Title 2
.................Post Title 3

Category 2
........Child Category 2.1
...........Sub-Child Category 2.1.1
.................Post Title 1
.................Post Title 2
.................Post Title 3

Category 3
........Child Category 3.1
...........Sub-Child Category 3.1.1
.................Post Title 1
.................Post Title 2
.................Post Title 3

share|improve this question

1 Answer 1

This would be the way I'd do it. Add the following to your functions.php;

class Walker_Category_Posts extends Walker_Category
{
    function start_el( &$output, $category, $depth, $args )
    {
        parent::start_el( $output, $category, $depth, $args );
        if ( $category->parent )
            return $output;

        if ( $posts = get_posts( 'posts_per_page=-1&no_found_rows=1&update_term_cache=0&cat=' . $category->term_id ) ) {
            $output .= '<ul>';
            foreach ( $posts as $post )
                $output .= '<li><a href="' . get_permalink( $post->ID ) . '">' . apply_filters( 'the_title', $post->post_title ) . '</a></li>';
            $output .= '</ul>';
        }
    }
}

And where you'd like to display the list, call;

<?php wp_list_categories(array('walker' => new Walker_Category_Posts)); ?>
share|improve this answer
    
Thanks for the handy function! I've inserted it into my functions.php file and it will display the cats, subcats.. but not the posts within the subcats. So, in essence I just get a listing of my categories and their hierarchy ... any input on why its not showing posts for the subcats?? –  revive Sep 14 '11 at 6:06

Your Answer

 
discard

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