A while ago I wrote a post on how to aggregate items from ‘the last 7 days’ using the Content Query Web Part in SharePoint 2007, which involved exporting the webpart and overriding the CAML query. Now in SharePoint 2010 it’s a much easier process to achieve the same result.
The CQWP now includes additional filters such as the PageQueryString and PageFieldValue filters. Also they have helpfully added the ability to provide a whole number value for date fields which will correspond to Today +/- the number of days. This is all helpfully explained in the inline help in the webpart properties pane (below).
We can now use this feature to setup the filters of our query to return items only from the last 7 days, in this example to return Article Pages. Constructing the filter for items in the last week we need to return pages with a date that is:
- greater than today minus 7 days AND
- less than or equal to today
This straight-forward query then gives us only the articles that we want to see in the results of the CQWP. Turning the default aggregation from this:
As an aside, to help with testing I needed to get the article date returned in the results. This was quickly achieved without having to edit any XSL by using another of the new additions to the Content Query Web Part in SharePoint 2010 – Slots. This simply allowed me to specify a particular field that I wanted to use as the description text in the default presentation style.