WordPress.org

Ready to get started?Download WordPress

Forums

Looping through / Grouping by Sub-Categories (2 posts)

  1. DDeacon
    Member
    Posted 1 year ago #

    I have posts under the following category structure:

    Destinations
    -- Alaska (5 posts)
    -- Antarctica (2 posts)
    -- Arctic (0 posts)
    -- Asia (1 posts)
    etc. etc.

    I'm looking to create a custom loop that "loops" through all the sub-categories (under Destinations), displays the category name (if posts exist under that category - as a header), then the post titles under that category.

    Example of my expected code output:

    <section>
       <h2>Alaska</h2>
       <ul>
       <li>Alaska post #1</li>
       <li>Alaska post #2</li>
       <li>Alaska post #3</li>
       <li>Alaska post #4</li>
       <li>Alaska post #5</li>
       </ul>
    
       <h2>Antarctica</h2>
       <ul>
       <li>Antarctica post #1</li>
       <li>Antarctica post #2</li>
       </ul>
    
       <h2>Asia</h2>
       <ul>
       <li>Asia post #1</li>
       </ul>
    
    ...etc...
    </section>

    I prefer to handle this via a loop and not another plug-in. Any assistance is much appreciated.

    Thanks.

    — Dennis

  2. JudaZuk
    Member
    Posted 11 months ago #

Topic Closed

This topic has been closed to new replies.

About this Topic