Forums

[resolved] Loop categories wordpress (6 posts)

  1. nachovidal
    Member
    Posted 6 months ago #

    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]

    Can someone help me out please!
    Thanx

  2. alchymyth
    The Sweeper
    Posted 6 months ago #

    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

    structure:

    <?php $all_cats = get_catgories();
    foreach( $all_cats as $cat ) : ?>
    QUERY AND LOOP WITH ONE CAT AT A TIME
    <?php endforeach; ?>
  3. nachovidal
    Member
    Posted 6 months ago #

  4. nachovidal
    Member
    Posted 6 months ago #

    `<?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.

  5. alchymyth
    The Sweeper
    Posted 6 months ago #

    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

    the link http://codex.wordpress.org/Function_Reference/get_categories has all the information how to get the category ids etc from the foreach loop.

  6. nachovidal
    Member
    Posted 6 months ago #

    10000 Thanks Alchymyth!!!
    Done a little modification and now it works perfect :)

Reply

You must log in to post.

About this Topic