4

I am building a site, using Views, that needs to filter the content for each month. I have created a date field on the custom content type, and I made a publish start and end date fields.

I need the view to change the content at the start of the new month. Can anyone please explain how to make a view only display content based on the current month?

2 Answers 2

3

In the latest versions of Views, you can use a date argument to do this. For example, you could select the node post date as a date to use with the argument, and then if you passed 2011-12 as the argument, it would limit the display to only nodes posted in December 2011. You can use any ISO date for this, too, so P1M, which means a period of 1 month, would create an argument for the current month. Check out http://en.wikipedia.org/wiki/ISO_8601 for an indepth explanation of a lot of different ISO date formats. All should work here, the only one you have to be careful of is the interval format; with drupal you need to use -- instead of / to separate them for hopefully obvious reasons.

If, however, you are wanting to group or aggregate your content by month, check out http://drupal.org/node/388140.

4
  • Hey thanks for being such a help jimajamma. Can you clarify what I am doing here. So in the view I go to contextual filters and select publish date (a custom field I created on a content type to specify the month to publish the article)... Dec 29, 2011 at 1:24
  • I can't use the post date because I plan to create the articles ahead of time and have them ready when the month changes... all updates automatic. Now I created two posts one with the publish date of december 2011 and one with the date of jan 2012... they both are showing. I tried to filter the content by the publish date and got nothing. I am confised as to how to make this filter correctly and push and pull content. Dec 29, 2011 at 1:24
  • I also didn't see any place to work out an argument... I need some help with this. Dec 29, 2011 at 1:25
  • Where do I attach this argument? (P1M) This is exactly what I need but don't see where to implement. Jan 1, 2012 at 6:46
0

For those who still looking for a way to figure out this one.

  1. Open your views UI

  2. Look to Page Settings -> Path

  3. Set the Path like this: "news/%". You can use any word you like, obviously.

  4. Go to "Advanced Tab" -> Contextual Filter -> Created Year. Use Defaults

Now you can filter your nodes by passing additional argument to your URL like this:

news/2015

news/2014

Thats all

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.