WordPress.org

Ready to get started?Download WordPress

Forums

Styling by Category using wp_get_archives (5 posts)

  1. FrPSh
    Member
    Posted 2 years ago #

    I'm building a fairly large site that has a "most recent posts" section on the main page.

    So far, I've been using the wp_get_archives function with good success to bring up a list of the most recent posts. However, I have different categories for different topics of posts, and I want to be able to style each post listed depending on what category it is from.

    Is this easily done with wp_get_archives? Can I find a way to identify and style each post depending on category?

  2. esmi
    Forum Moderator
    Posted 2 years ago #

    wp_get_archives only displays a list of links to post - not the actual posts themselves. Are you talking about styling each one of these links differently? If so, that not possible with wp_get_archives.

  3. FrPSh
    Member
    Posted 2 years ago #

    Yeah, sorry, that's what I want to do. Style each link differently depending on category.

    If this isn't possible with wp_get_archives, is there a similar function that would provide for this?

  4. esmi
    Forum Moderator
    Posted 2 years ago #

    Not a single function, no., You need to build a script that used custom queries to grab the relevant group of posts by date, then in a loop, grab the first category assigned to each post and add the category slug as a class to the final generated link.

  5. FrPSh
    Member
    Posted 2 years ago #

    Not trying to be needy, but I'm not yet a pro at PHP. Any chance you could flesh out what you're proposing here?

Topic Closed

This topic has been closed to new replies.

About this Topic