Support » Fixing WordPress » Yearly archive index with titles, images, and descriptions

  • 10010110

    (@10010110)



    I’m trying to create an archive index where there are links to the posts (of a certain category) by year, but instead of just the year numbers (as in the default yearly archive list that I get when using wp_get_archives(‘type=yearly’)) I want to have custom titles, images, and optionally descriptions. The best thing that comes to my mind right now is a custom post type where I create posts with a manually-created link to the specific yearly archive.

    Is that the way to go or is there a different approach that I haven’t thought of yet?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    Is it each year for which you want custom titles, images, and descriptions? If so, I agree that a custom post type will work. Depending on how you want to use the data, a custom taxonomy might make more sense. Custom data can be stored in term meta. A third option would be a custom DB table, but is probably overkill in this case.

    You shouldn’t need to manually create a link to an annual archive though. Presumably the year is part of the post type’s (or term’s) data. In the loop that outputs year post type data, dynamically assemble the archive URL from available data.

    Let’s assume each year post’s title is the year for that post. Output a link to the annual archive like so:
    echo '<a href="' . site_url("/{$post->post_title}/") . "\">Archive for {$post->post_title}</a>\n";

    10010110

    (@10010110)

    Thanks for your reply.

    Yes, each year will have a custom title, image, and description.
    The whole thing has another intricacy: I want to list the posts of a certain year and a certain category only. I guess I’m not going with a standard archive template/URL but going to create a custom post template with a custom loop, and I’m going to use a custom field for the year.

    Moderator bcworkz

    (@bcworkz)

    FWIW, you don’t necessarily need to use a custom template to make custom queries. What’s shown on any post listing can be further constrained by modifying the default query through an action hook. As long as you are happy with the default template’s output, you don’t need a custom template.

    Even a default template’s output can sometimes be modified through filter hooks. There’s nothing wrong with a custom template, but it’s not always the ideal solution.

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.