I wanted to make an "on this day in history" block to see if there are any interesting patterns with my music listening history. It is doable with a View block in Drupal with a little bit of setup. The block shows a list of albums that I listened to on today's date from every year in the past (5/15/2024, 5/15/2023, etc.).
You will be making a block with at least two contextual filters that look at the current month and current day. They will only allow content that match today's month and date. Setting up a block like this is excellent practice for working with contextual filters in Views.
Steps
Setup your View
Make a view with a block set to only show whatever content type you are posting (Page, Article, etc.).
Setup the Fields
Add whatever fields you want to display in your block. Title will work as a bare minimum.
Setup the Contextual Filters
You are going to create two contextual filters which is located in the Advanced area.
- Select the filter for "Content: Created month" and click apply. Under "When the filter value is NOT available", choose Provide Default Value and set the Type to Current Date. Click apply this display.
- Select the filter for "Content: Created day" and click apply. Under "When the filter value is NOT available", choose Provide Default Value and set the Type to Current Date. Click apply this display.
You should now have two Contextual filters:
- Content: Created month (Default: Current date)
- Content: Created day (Default: Current date)
Setup the Filter Criteria (optional)
If you are ok having this current year's posts in your block then skip this. If you need to NOT have posts from the current year in your block, you need to set up one more filter.
- Add a new filter and choose what field you are using as a source for your date. Mine is "Content: Authored on".
- For the operator select "Is less than.
- For the value type select "An offset from the current time such as "+1 day" or "-2 hours -30 minutes"
- For the value, enter "first day of this year"
- For the granularity, select day.
Add the Block to your Site
Now you can place your new block wherever you want and it will show you a list of content from the current day.
Add new comment