WordPress.org

Ready to get started?Download WordPress

Forums

List subcategories and 4 posts of each. (4 posts)

  1. rustyrich
    Member
    Posted 2 years ago #

    When I am on a category page IE http://www.mysite.com/mycategory/, I want to display all the subcategories of that category. I also want to display 4 posts from each of the subcategories. Any help would be great.

    So basically:

    .....................................
    . Category Page .
    . .
    . SubCategory .
    . Post | Post | Post | Post .
    . .
    . SubCategory .
    . Post | Post | Post | Post .
    . .
    . SubCategory .
    . Post | Post | Post | Post .
    .....................................

  2. rustyrich
    Member
    Posted 2 years ago #

    Can anyone give a clue as to how this works?? Any help would be much appreciated!!

  3. alchymyth
    The Sweeper & Moderator
    Posted 2 years ago #

    what theme are you working with?
    do you have a layout designed?
    do you want to do this for each category?
    or only for top level categories?
    do you still want to show a certain number of posts for the parent category?

    something to start:
    - to get the category id of the category archive page: get_query_var('cat')
    - to get the sub categories, use the 'parent' parameter of http://codex.wordpress.org/Function_Reference/get_categories
    - use a foreach loop to loop through these sub categories;
    - use either get_posts() http://codex.wordpress.org/Template_Tags/get_posts or WP_Query() to get the posts for each of these sub categories http://codex.wordpress.org/Class_Reference/WP_Query

  4. rustyrich
    Member
    Posted 2 years ago #

    Thank you! I will take a look at these references.

    As far as theme, I'm developing my own theme and basically all page templates will never show posts for the parent category but only the subcategories and 4 posts of each.

Topic Closed

This topic has been closed to new replies.

About this Topic