Categories, date archive pages not filtering posts?
It’s a common problem: the category and date archive pages on a Sharepoint blog site stop working and users see all posts instead of a filtered view. It’s easy enough to insert a new “blog tools” web part (which a well known bug breaks if you edit the category.aspx or date.aspx pages). If that doesn’t do it, there are several articles about how to fix the category page – like this one: blog.hametbenoit.info/Lists/Posts/Post.aspx?ID=584
The fix involves restoring a CAML query that Sharepoint mysteriously strips out. The same approach applies to the date archive page but the specific query is different and hasn’t received as much attention, so I thought it worthwhile spelling out what needs to be done.
Restoring the missing CAML query
In Sharepoint Designer, open your blog site and navigate to the date.aspx page in the posts list.
It’s always a good idea to make a quick copy of ANYTHING you edit in Sharepoint, before diving in. Then, edit it in advanced mode.
Do a search for “<Query><OrderBy><FieldRef Name=”PublishedDate” ” to locate the section of the posts list view web part that needs to be edited.
After the closing orderby tag “</OrderBy>”, add the following CAML query:
<Where><And><And><Geq><FieldRef Name=”PublishedDate”/><Value Type=”DateTime” IncludeTimeValue=”TRUE” StorageTZ=”TRUE”><GetVar Scope=”Request” Name=”StartDateTime”/></Value></Geq><Lt><FieldRef Name=”PublishedDate”/><Value Type=”DateTime” IncludeTimeValue=”TRUE” StorageTZ=”TRUE”><GetVar Scope=”Request” Name=”EndDateTime”/></Value></Lt></And><Eq><FieldRef Name=”_ModerationStatus”/><Value Type=”ModStat”>0</Value></Eq></And></Where>
It should look like this:
Click to enlarge »
Since this is generic code with no guid’s, and doesn’t appear to have changed much over the years, it’s “safe” to use and should work in any blog site in any version of SP.
Now, save the page, open it in the browser, restore the “blog tools” web part which will inevitably be broken and check that your filtering is working again.
The straw that broke the CAML’s back
WHY the CAML query gets stripped out remains a mystery and is another example of the questionable development standards in Sharepoint, the platform’s fragility and Msft’s lack of focus on the user experience. But at least now there’s a quick and easy fix.