WordPress.org

Ready to get started?Download WordPress

Forums

List posts by child categories (11 posts)

  1. Shirohagen
    Member
    Posted 6 years ago #

    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:

    Landscapes
    Post 1
    Post 2

    Portraits
    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!

    ®

  2. mores
    Member
    Posted 6 years ago #

    *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 :)

  3. Rodeo Imagination
    Member
    Posted 6 years ago #

    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...

    Gallery:

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

    Is it that what you want?...

  4. flick
    Member
    Posted 6 years ago #

    This looks like a really promising plugin: Article Directory

  5. mores
    Member
    Posted 6 years ago #

    @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 :)

  6. flick
    Member
    Posted 6 years ago #

    @mores: I see where you're coming from now ;) I'm looking forward to seeing this potentially releasable theme!

  7. mores
    Member
    Posted 6 years ago #

    @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:

    <?php
    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>
    	<ul>
    	<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; ?>
    	</li>
    	</ul> 
    
    <?php endforeach; ?>

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

  8. mores
    Member
    Posted 6 years ago #

    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");
  9. flick
    Member
    Posted 6 years ago #

    @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!

  10. mores
    Member
    Posted 6 years ago #

    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 :)

    Cheers

  11. mores
    Member
    Posted 6 years ago #

    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: http://wordpress.org/support/topic/146589?replies=5
    But, that does not work with the weird categorylisting that we're doing :(

Topic Closed

This topic has been closed to new replies.

About this Topic