Support » Plugins » List posts by child categories

  • Hi guys

    I was wondering: Is it possible to list posts by category, for each child category of a particular parent?

    Let me explain…

    I’m building a photographic portfolio and I have a parent category of ‘gallery’ under which I can create as many child categories as I like: ‘landscapes’, ‘portraits’ etc..

    I’d like to have a template page which automatically lists the posts in each child category of the gallery parent, so it would output:

    Post 1
    Post 2

    Post 3
    Post 4

    This way I can add categories and posts and the overall gallery page will always show them all without being edited manually.

    Any ideas? Is this possible or will I need to find a plugin of some sort?

    Any help would be appreciated!


Viewing 10 replies - 1 through 10 (of 10 total)
  • *bump* ๐Ÿ™‚
    I’m currently looking into something like this as well.
    Ideally, since my navigation is just a list_cats() nav, I want a categorie’s posts listed by the subcategories just like shirohagen has demonstrated.

    help us ๐Ÿ™‚

    This will be displayed in main index page? or in an inside “gallery category page”?

    Because if it’s in main page, you can call an estrict loop for posts of one category, which can display in an especific way a series of posts info… like…


    [image 3] [image 2] [image 1]
    date date date

    Is it that what you want?…

    This looks like a really promising plugin: Article Directory

    @shiroujune: the main index page is already heavily modified to resemble a Magazine Layout with 4 or 5 loops ๐Ÿ™‚
    I would like to create a page template that lists all of category X’s subcategories with corresponding posts.
    Specifically, it is a biography page, where there is a main “Bio” category, and the subcategories are “on-air-experience” and “off-air-experience” and “radio experience”, current jobs are categorized accordingly.

    @mosey: will have a look. I was looking more into a template/functions.php solution since I want this theme to be as plugin-independand as possible. Maybe this will be my first releasable theme ๐Ÿ™‚

    @mores: I see where you’re coming from now ๐Ÿ˜‰ I’m looking forward to seeing this potentially releasable theme!

    @mosey, I don’t think I understand what you’re implying. But once the site is finished I’ll post the link. It’s my first project that involves multiple loops and a completely category-based navigation (except for “home” and “contact”)

    But, I have searched, and searched, and tried, and finally found this gem:

    global $wpdb;
    $categories = $wpdb->get_results("SELECT $wpdb->terms.term_id AS id, name, description from $wpdb->terms INNER JOIN $wpdb->term_taxonomy ON $wpdb->terms.term_id = $wpdb->term_taxonomy.term_id WHERE parent = '$cat' ORDER BY name ASC");
    foreach($categories as $category) :
    <h2><?php echo $category->name; ?></h2>
    	<li><a href="<?php echo get_category_link($category->id);?>"><b><?php echo $category->description; ?></b></a>
    Posts on this campaign:
    <?php global $post;
    $myposts = get_posts("category=$category->id");
    foreach($myposts as $post) : setup_postdata($post);
    - <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    <?php endforeach; ?>
    <?php endforeach; ?>

    Does exactly what I want. List Categories with the corresponding posts.

    Hmmm … anyone see why this code outputs just the recent 5 items?
    Yes, WP is set to display 10 at a time *scratches-head*

    EDIT: figured it out:

    $myposts = get_posts('numberposts=999&'."category=$category->id");

    @mores: I was responding to this:

    I was looking more into a template/functions.php solution since I want this theme to be as plugin-independand as possible. Maybe this will be my first releasable theme ๐Ÿ™‚

    And assumed that the plan was to release it as a theme, and to make it easier for everyone, it shouldn’t have to rely on a plugin?

    Apologies if I got the wrong end of the stick!

    oh, ok, sorry. the wink-smiley threw me off …
    No apologies necessary.

    I hate themes that require me to install plugins where I don’t understand what they’re needed for. So I want to do an out-of-the-box magazine/newspaper theme and I’m well on my way ๐Ÿ™‚


    Okay, I’m back with another problem.
    Now I want to show only X posts under each category, and make use of the
    <?php next_posts_link('Next Entries ยป', '0');ย ?>
    tag. But, when I click it, I still only get the first X.
    I assume it has something to do with an offset, and I need to calculate it by using the “paged=2” parameter and multiply it by “numberofposts” to get an “offset” …. but how ?

    EDIT: okay, I found a solution here:
    But, that does not work with the weird categorylisting that we’re doing ๐Ÿ™

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘List posts by child categories’ is closed to new replies.