Home > CQWP > Custom Blog Rollup Using Content Query Web Part

Custom Blog Rollup Using Content Query Web Part

There are a few posts dealing with CQWP customization but most of them use the publishing pages. A few requests have been posted to customize blog posts using CQWP and there is something specific to this request: the CQWP does not output the blog post body out of the box. Before I describe the process, I should give credit to the blog post by Heather Solomon (2007, but still valid for 2010).
There are two main steps in this process: customize the ItemStyle and the CQWP. You can find the reference on adding properties to the CQWP at this MSDN article.
So, we export the CQWP and edit the line that has CommonViewFields to become Body, Note
Here, Body is the post body text and Note is its type (yes, it’s not RichHtml as you may think), but how do we know? You check the schema file at \14\TEMPLATE\FEATURES\DiscussionsList\Discuss
Now that we have the field available in the CQWP, we edit the item style. The ItemStyle.xsl file lives in the Style Library in your site collection (only there, one style library per site collection) inside the folder XSL Style Sheets (that’s easy to figure out). You download the file and open it in a text or xml editor. Here, we will copy the default style and paste it under the original (starts with – around 67 lines). Of course, we need to name our style – I replaced the first line by

in that block (close to the end of the template). Here, I am taking the first 75 characters of the clean text and added a link to see the full post.
Finally, I added the template that strips out html tags right after the closing tag of my custom template (). The removeMarkup template is available from Heather’s post toward the end and is clearly marked.
Save the xsl file and re-upload to the styles library (xsl style sheets folder). You need to publish a major version for this to work (not only check it in).
Now, you add a web part to your page based on the exported and adjusted one (under the web part groups, locate the Upload web part then select from imported web parts). Configure your CQWP and select your new item style (do not add Body; in the Description field!). If you did not have typos, you should see something similar to the above screen shot. If your itemstyle is not correct, your CQWP will not show and will give error (add ?contents=1 to the url and delete it, then roll back to the previous version of the itemstyle until you fix the custom one). See more on Heather’s blog on how to see available fields and find types etc.
Categories: CQWP Tags: blog rollup using CQWP
  1. March 9th, 2012 at 12:45 | #1

    Hi Abed,

    Really good post. Thanks. There is little out there on how to customise the CQWP to display blog posts. I’ve used Heathers blog on this in the past to help display article pages on SP2007. That worked with no major problems.

    Unfortunately I’m struggling with doing the same to Blog posts. Your article is good but I lose my way towards the final 3rd.

    Are you able to provide the full code to your xsl:template? I know my way around SharePoint but I’m not so techy. If you could help to explain it step by step to a simpleton like me I’d be grateful. :)

    Regards,
    Marc Ryan

  1. No trackbacks yet.