Quantcast
Channel: WordPress.org Forums » All Posts
Viewing all articles
Browse latest Browse all 134470

DDeacon on "Looping through / Grouping by Sub-Categories"

$
0
0

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


Viewing all articles
Browse latest Browse all 134470

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>