I've created my main site with two blog subsites. I want to show the last 5 "recent" (under 90 days) posts on the main page of the main site. A Content Query Web Part would be perfect here, but unfortunately, that is only available in MOSS. There is an Enhanced Content Query Web Part on CodePlex, but it derives from the CQWP which still requires MOSS. Fortunately, SharePoint designer has a DataFormWebPart which can perform the rollup.
Here are the steps.
- Open the page where you want the roll up in SharePoint Designer.
-
Optional - If you are unfamiliar with this process, you may want to create this is in a test page, and then copy it to the real page later.
- Create a Pages document library if it does not already exist
- Site Actions > Create > Web Part Page
- Name: Pages
- Don't display on Quick Launch
- Document Template: Web Part Page
- In the Pages Document Library, create a new Web Part Page
-
Create a Data Source
- Data View > Manage Data Sources … > Connect to another Library
- Enter your site name and URL when prompted
- You should be able to navigate to the Posts document library.
- In Split or Code mode, put the cursor where you want the data to appear. If you put it into an existing web part zone, you will be able to edit it within a web page as a web part. Note that the cursor should not be in an existing Web Part, such as a ContentEditorWebPart. It could also be within a <TD> or <Div>, etc.
- Data View > Insert DataView in the SPD menu.
- In the Data Source Library, choose Posts
-
In the design pane of the page, enter the Common Data View tasks by clicking on the arrow in the upper-right corner of the DVWP.
- Set the filter Criteria to Approval Status Equals 'Approved'.
- Sort by Created Descending
- In Edit Columns, Use Title and Created
- In Properties > Paging > Limit the total number of items displayed to 5
-
Make a link from the title field
- Hover over a title in the title field and click on the arrow
- Change the field type to a Hyperlink
- Leave the Text to display as {@Title}
- Clear out the Address text box dropdown
- Next to the Address text box dropdown, click the fx button > Path >OK
- Click fx > Id > OK. The address should be {@FileDirRef}{@ID}
- Click Ok to exit the dialog box.
- Switch to Code view in SharePoint Designer
- Replace {@FileDirRef}{@ID} with /{@FileDirRef}/Post.aspx?Id={@ID}
-
Clean up
- The data is self-explanatory enough that we don't need the headers. I removed the entire row containing the <th> tags.
Besides limiting the number of posts in the rollup to five, I'd also like to show items that are not too stale, say no more than 90 days old. Here are the steps
- Select the DFWP Common Data View Tasks in the Design View > Filter
- Set Field Name to Created
- Set Comparison to Greater Than
- Set Value to Current Date
- In code view, find the reference to Today within the DFWP's select statement
- Change Today to Today OffsetDays='-90'
As I researched this, I came across this post that suggests we could have a roll up of posts from all subsites instead of two separate lists, but that's a project for another day perhaps.
Note that is was originally published 7/13/2008, but it got lost somehow.