Support » Themes and Templates » Twenty Eleven: Help with custom loop

  • Hi

    I decided to use the default “Twenty Eleven” theme and I’m trying to customise the “other recent posts” loop. By default the loop simply lists all recent posts chronologically. What I’d like to do is group them by category. I’ve failed to achieve this so far and wondered if anyone could offer some pointers.

    What I’ve got so far is a series of loops (1 for each category) using WP_Query as follows:

    [Code moderated as per the Forum Rules. Please use the pastebin]

    As you can see I’ve had to hard code each category in this loop which isn’t very good – what if I add new categories etc.

    What I’d like to achieve is some order in the loop by grouping the recent posts by category along the lines:

    category: category 1 (a label)
    Post 1 in category 1 (the posts)
    Post 2 in category 1

    Category: category 2 (the next category label)
    Post 1 in category 2 (the posts)
    Post 1 in category 2

    Can anyone offer some pointers on how I might tackle this please ?

    You can see the loops I’ve got so far at:

    Thanks for any help

  • The topic ‘Twenty Eleven: Help with custom loop’ is closed to new replies.