Views comes with a disabled view named "Archive". It will display all content, by month.

I want something very similar, but by year, so I'll have a block like this:

Where the numbers in parenthesises are the number of archived post of the year. The year links to a list with all the posts for the year.

Is there a way to tweak the "Archive" view to give me this?

Or is there another way to create a yearly archive block?

Comments

aaron.axvig’s picture

In Drupal 11.2:

  1. Clone the Archive view and edit that clone.
  2. By default you will be on Displays -> Block.
  3. Add a Contextual filter using Created year with "Display a summary" set.
  4. Rearrange -> remove the other Created year + month contextual filter.
  5. This gets you the block looking exactly like you describe.  But the links don't work.  The links are to /archive/2025, and the /archive/ path is handled by the original Archive view, which is expecting /archive/202506 (year plus month).
  6. Continue editing your duplicate view.
  7. Switch to Displays -> Page
  8. Fix the contextual filters there exactly like you did for the Block display.  This makes your Page expect to see just the year in the path.
  9. Page settings -> Path -> change to /archive-duplicate.  This makes your page listen at that path.
  10. Now you can test a URL like /archive-duplicate/2025 and that should work.
  11. I think the Block display URLs will automatically update to point to that path as well.

Of course having URLs containing /archive-duplicate/ is undesirable.  After going through this process you should have the knowledge needed to set it up the way you want, which may include customizing the stock Archive view to not squat on the /archive/ path so that you can use it.  Or just use /archives/ for your duplicate.

I have not figured out how to get the months nested as nodes under each year, which is what I want.