• Hi,

    I’ve searched and searched the forums for an answer to this … and I should start out by saying I’m not very proficient in PHP.

    I have a book review website that has four main categories. Each category has multiple subcategories. On the category page (using the category template), I would like to list the posts by subcategory.

    Currently, all posts display under the parent. I want them to display like this:

    PARENT CATEGORY

    Subcategory 1
    • Post 1
    • Post 2

    Subcategory 2
    • Post 3
    • Post 4

    etc …

    Any clue how to do this? I can’t figure it out.

    Thanks in advance!

Viewing 7 replies - 1 through 7 (of 7 total)
  • You cannot do that without creating some custom Category_Templates and custom multiple Loops in it.

    Thread Starter jmsnyder23

    (@jmsnyder23)

    Well I have a custom category template, and a custom loop already to call the posts in the category. What I’m not sure of is how to create a second loop that will return the posts by their subcategory.

    Any suggestions?

    I have a custom category template, and a custom loop already to call the posts in the category

    Hmmm… There must be something wrong in your setup because you don’t need any special custom Loop in a category template! WP knows better what to display there than you do…

    Thread Starter jmsnyder23

    (@jmsnyder23)

    You’re not really helping.

    I’ve found about 5 posts asking the exact same question (including mine) and no one has an answer 🙁

    Is this really that hard?

    I wrote this up at my site WordPressIntoCMS.com. I hope this is what you were after.

    Many people on the WordPress.org support forum are asking how to do this.

    Here is the simple solution I came across. It will allow you to display the title of a child category without displaying the parent category.

    Put this code in your template:

    [php]<?php
    $category = get_the_category();
    echo $category[1]->cat_name;
    ?>[/php]

    (Adapted from this code at WordPress.org.)

    The [1] tells it not to pull the parent category which would be [0] but instead to pull the child category which is [1]. If your hierarchy contains more layers simply change the number accordingly.

    I’ve just come across this post, and I’ve been asking the same thing. @cakeychan, there must be some kind of way to do this dynamically, that should be the benefit of a dynamic application.
    @moshu, please have a little more patience with us noobs. We are only asking for help.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘How to display posts by subcategories’ is closed to new replies.