Profile picture for user admin
Daniel Sipos
26 Oct 2012

Looking on the drupal.org forum I came across a user in need of some help. He wanted to create a block which displayed only today’s news. If there were no news posts today, the block was to remain empty.

I mean it's such a simple thing, but thinking about it I realized I had never done anything like that before. Usually the Views blocks displaying simple content are about the latest published pieces of content or stuff like that.

So I helped him do it and decided to write this post on how one can accomplish that.

You should have your Content Type of choice created (let’s say Articles) and then add a new View -> block -> Articles.

Make sure that the View filters restrict the results to Published Articles. If you are using taxonomy for your content, you should also filter it by that - your choice. Also, in case there are more Articles posted in any given day and you want them all showing in the block, you may want to Sort them by date descending.

Now, for the good stuff. Add a new Contextual Filter Content: Created day. Under When Filter Value is Not Available, check Provide default value of the type: Current Date.

Apply, and test your View. You can add all sorts of fields, rewrite their output, and all sorts of other modifications but this is how you get Views to show content authored today.

Hope this helps.

Profile picture for user admin

Daniel Sipos

CEO @ Web Omelette

Danny founded WEBOMELETTE in 2012 as a passion project, mostly writing about Drupal problems he faced day to day, as well as about new technologies and things that he thought other developers would find useful. Now he now manages a team of developers and designers, delivering quality products that make businesses successful.

Contact us

Comments

Alex 10 May 2013 01:05

Thanks! it works.

Hi This works great. Do you also know how to make sure that I display an article which was either Posted/Created today or Updated today. More weight should be given to update day and then post day.

I tried adding contextual filter, "Updated Day" in the same manner as you said, but it didn't display an older article which was modified/updated today.

Daniel Sipos 24 Jul 2013 13:50

In reply to by Alex (not verified)

Hey there,

Hey there,
You added the Updated Day contextual filter after the Created Day contextual filter or did you replace the latter? If you did the first, I am not surprised :)

Nuno 22 Jul 2013 17:52

< 24 hours

Hi Danny,

How would you do this if you wanted to show all articles not only front the current date but from the previous 24 hours as well?

Let's say that it's 2 am and I have no articles from today so I would like to display all articles from the previous 24 hours.

Can you give me a hint on how to implement this filter?

Thank you for your hard work with WebOmelette. It's excellent!

Daniel Sipos 24 Jul 2013 13:39

In reply to by Nuno (not verified)

I tried to recreate the

I tried to recreate the problem but could not find the solution. Have you had any luck? Keep me posted if you do :)

Thanks!

Kimberly 19 Aug 2013 22:50

OMG! It Works

You don't know how much time I spent trying to figure this out! and in less than 2 minutes I had created the view I wanted all along! Thank you!

Jeff 07 Jul 2016 22:13

Can't you simply do this by

Can't you simply do this by using a standard filter to check when the node was published?

Flo 26 Feb 2018 14:09

can't use current date !

The apply button don't work with this option ; i can't save .

Add new comment