Title: Loop categories wordpress
Last modified: August 20, 2016

---

# Loop categories wordpress

 *  Resolved [nachovidal](https://wordpress.org/support/users/nachovidal/)
 * (@nachovidal)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/loop-categories-wordpress/)
 * Hi,
    I’m building a template that displays all categories including the posts
   within these categories on the homepage (one big scroll page).
 * The posts need to be ordered by category. I’v tried a 1000 thing, but nothing
   seems works.
 * now i’m doing it like this, but i have to hardcode al the categories i want to
   show. I’m looking for a dynamic version!
 * _[code moderated - please follow [the forum rules for posting code](http://codex.wordpress.org/Forum_Welcome#Posting_Code)]_
 * Can someone help me out please!
    Thanx

Viewing 5 replies - 1 through 5 (of 5 total)

 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/loop-categories-wordpress/#post-2407072)
 * try to build your code on a foreach loop using `get_categories()` to get all 
   categories of your site; [http://codex.wordpress.org/Function_Reference/get_categories](http://codex.wordpress.org/Function_Reference/get_categories)
 * structure:
 *     ```
       <?php $all_cats = get_catgories();
       foreach( $all_cats as $cat ) : ?>
       QUERY AND LOOP WITH ONE CAT AT A TIME
       <?php endforeach; ?>
       ```
   
 *  Thread Starter [nachovidal](https://wordpress.org/support/users/nachovidal/)
 * (@nachovidal)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/loop-categories-wordpress/#post-2407087)
 * this is the code
    [http://pastebin.com/embed_js.php?i=DhDe1TdH](http://pastebin.com/embed_js.php?i=DhDe1TdH)
 *  Thread Starter [nachovidal](https://wordpress.org/support/users/nachovidal/)
 * (@nachovidal)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/loop-categories-wordpress/#post-2407097)
 * > `<?php $all_cats = get_catgories();
   >  foreach( $all_cats as $cat ) : ?> QUERY
   > AND LOOP WITH ONE CAT AT A TIME <?php endforeach; ?>`
 * Thanks for the reply!
 * How do you mean one loop at a time?!
 * the whole idea is to show al categories in a “list” including their posts and
   show the category title above the first post of the category.
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/loop-categories-wordpress/#post-2407099)
 * the snippet was to show how to get all categories dynamically;
 * this ‘QUERY AND LOOP WITH ONE CAT AT A TIME’ is the space for you to build your
   list;
    i.e. where you add your code, just replace the fixed category ids, slugs,
   and names with dynamic ones;
 * example (totally untested):
    [http://pastebin.com/Wz4T0w2y](http://pastebin.com/Wz4T0w2y)
 * the link [http://codex.wordpress.org/Function_Reference/get_categories](http://codex.wordpress.org/Function_Reference/get_categories)
   has all the information how to get the category ids etc from the foreach loop.
 *  Thread Starter [nachovidal](https://wordpress.org/support/users/nachovidal/)
 * (@nachovidal)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/loop-categories-wordpress/#post-2407141)
 * 10000 Thanks Alchymyth!!!
    Done a little modification and now it works perfect
   🙂

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Loop categories wordpress’ is closed to new replies.

## Tags

 * [categories](https://wordpress.org/support/topic-tag/categories/)
 * [category](https://wordpress.org/support/topic-tag/category/)
 * [loop](https://wordpress.org/support/topic-tag/loop/)

 * 5 replies
 * 2 participants
 * Last reply from: [nachovidal](https://wordpress.org/support/users/nachovidal/)
 * Last activity: [14 years, 6 months ago](https://wordpress.org/support/topic/loop-categories-wordpress/#post-2407141)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
