How can I display only one post from each category? (3 posts)

  1. arro08
    Posted 4 years ago #

    I've started to build a blog on the Shaken Grid-theme, but I can't figure out how to customize the first page the way I want it.

    I only want to show the latest post from each category on the index page, for all of the categories. And I want to show them in chronological order, so that the category containing the most recent post will appear first on the first page.

    Here's the code that should print out the posts on the index page.

    [code moderated - please use the pastebin for any code over the forum limit of 10 lines]

  2. david.bailey
    Posted 4 years ago #

    Without writing the code here, what I would do is use get categories to return all the categories that have posts in an array. Then I would use WP_Query and iterate through all the categories in the array for the recent post in that category.

  3. arro08
    Posted 4 years ago #

    Thank you David! Unfortunately my coding knowledge is quite limited, and I have no idea how to use the advice you just gave. Could you help me implement it in the code I use to put the posts on the first page?

    This code: http://pastebin.com/pSDY5x32

Topic Closed

This topic has been closed to new replies.

About this Topic