Ever wondered how to have the Content Query Web Part (CQWP) aggregate SharePoint blog posts from the SharePoint Blog site templates? Oh wait, that’s already possible. How about aggregating blog posts, customizing the XSL styling and being able to display the first 200 characters of the post as a preview?
Believe it or not, I couldn’t seem to find a single definitive blog post on how to do this so I’ve decided to write one up myself.
Step 1
Assuming you already have your Blog sites setup, add a Content Query Web Part to the page in which you’d like to have the posts aggregated onto. Configure the Web Part to your liking. It would look something like this:
Step 2
Using SharePoint Designer, check-out and open the ItemStyle.xsl Style Sheet from http://yourserver/Style Library/XSL Style Sheets/
Step 3
Follow all the steps in this blog post. It will give you a good overview on how to customize the Content Query Web Part to aggregate and display News Article items along with the quick summary display and some other item properties.
The result of my customized XSL Template looks like this:
<xsl:template name="LargeTitleWithDescription" match="Row[@Style='LargeTitleWithDescription']" mode="itemstyle"> <xsl:variable name="SafeLinkUrl"> <xsl:call-template name="OuterTemplate.GetSafeLink"> <xsl:with-param name="UrlColumnName" select="'LinkUrl'"/> </xsl:call-template> </xsl:variable> <xsl:variable name="SafeImageUrl"> <xsl:call-template name="OuterTemplate.GetSafeStaticUrl"> <xsl:with-param name="UrlColumnName" select="'ImageUrl'"/> </xsl:call-template> </xsl:variable> <xsl:variable name="DisplayTitle"> <xsl:call-template name="OuterTemplate.GetTitle"> <xsl:with-param name="Title" select="@Title"/> <xsl:with-param name="UrlColumnName" select="'LinkUrl'"/> </xsl:call-template> </xsl:variable> <xsl:variable name="LinkTarget"> <xsl:if test="@OpenInNewWindow = 'True'" >_blank</xsl:if> </xsl:variable> <xsl:variable name="Created"> <xsl:value-of select="ddwrt:FormatDateTime(string(@Created) ,1033 ,'MM-dd-yyyy')" /> </xsl:variable> <xsl:variable name="Author"> <xsl:call-template name="OuterTemplate.GetGroupName"> <xsl:with-param name="GroupName" select="@Author"/> <xsl:with-param name="GroupType" select="'User'"/> </xsl:call-template> </xsl:variable>
<div id="linkitem" class="item"> <xsl:if test="string-length($SafeImageUrl) != 0"> <div class="image-area-left"> <a href="{$SafeLinkUrl}" target="{$LinkTarget}"> <img class="image" src="{$SafeImageUrl}" alt="{@ImageUrlAltText}" /> </a> </div> </xsl:if> <div class="link-item-large"> <xsl:call-template name="OuterTemplate.CallPresenceStatusIconTemplate"/> <font size="2"><xsl:value-of select="$Created"/></font><br/> <a href="{$SafeLinkUrl}" target="{$LinkTarget}" title="{@LinkToolTip}" style="color:black"> <xsl:value-of select="$DisplayTitle"/> </a> <div class="description"> <span style="padding-left: 5px; font-size: smaller; text-decoration: none;"> Posted by <xsl:value-of select="$Author" /><br/><br/> </span> </div> <div class="description" style="padding-left:5px; color:#333333;"> <xsl:value-of select="substring(@Description, 0, 200)" disable-output-escaping="yes"/> <a href="{$SafeLinkUrl}" target="{$LinkTarget}" title="Read More">...</a> </div> </div> </div> </xsl:template>
Unfortunately, if you check this in, publish it and look at your CQWP, it won’t display the summary text of the blog post. It will look something like this:
So after much head scratching and googling, I came across this blog post and this blog post that gave me some hints as to why this doesn’t work with the Body field of SharePoint blog posts. Apparently the Blog Site template and the Posts Document Library contain more than one Content Types (one for posts, one for comments?). But wait! He says we can override the Content Query Web Part. Unfortunately… there doesn’t seem to be an available BaseType for blogs.
After some more sleuthing I finally see something interesting on the 2nd page of my google search. A PowerPoint Slidedeck from SharePoint Conference 2008 being stored on a Chinese SharePointer’s SharePoint Site! Good thing he didn’t have all the slides translated already :p And thank you Sean Squires from the ECM Team for including some really awesome slide notes. Slide 15 did it for me. So onwards with our cuztomizations…
Step 4
Export the configured CQWP and open it with a text editor. There will be 3 lines that will need editing. The first one is this one:
<property name="ListsOverride" type="string"/>
You’ll want to change it to reflect this:
<property name="ListsOverride" type="string"> <![CDATA[<Lists><List ID="81B49BFB-E218-46D4-A697-683FE7F286ED"/> <List ID="0CC1695B-1E54-45C5-9825-67DE219A2B4C"/></Lists>]]> </property>
Heather Soloman has a nice post that explains how to retrieve a list’s GUID. The second line you’ll need to change is this one:
<property name="DataColumnRenames" type="string" />
Update that property to reflect this:
<property name="DataColumnRenames" type="string">Body,Description;</property>
The 3rd line that needs to change is
<property name="CommonViewFields" type="string" />
It should now look like this:
<property name="CommonViewFields" type="string"> ExternalUrl,URL;PublishingPageImage,Image; Body,Description;</property>
Save your Web Part file as something other than the default file name.
Step 5
Upload your customized Web Part into your Site Collection’s Web Part Gallery. It would probably be helpful to give it a unique name and group.
Step 6
Add the new web part to your page and voila!
Nice writeup and much needed as well.
Thanks. π
this is god send..I was looking for this to post blogs on my MOSS 2007 front page dynamically for the portal from the SharePoint blogs. I just have to look into a way to put one and only the latest post on the content query webpart. i should be able to maniupalate this…
thanks again.
I get this error when I check in the itemstyle.xsl with your template.
Unable to display this Web Part. To troubleshoot the problem, open this Web page in a Windows SharePoint Services-compatible HTML editor suc
Re: Z:
You need to replace any punctuation from the copy-paste with real ‘”‘, ”’, and ‘…’ chars…
Caught me out too…
My problem is, if I do step 4 with the ListOverride, the Web Part does not display *anything* (I will check to see if the GUID shown here is a sample…), but if I take it out, I still get no body synopsis…
Hey Mark, the copy paste should work as is, but if it doesn’t let me know which parts need to be updated. The GUIDs will be unique to your environment.
Hey Henry
After banging my head with table for 3 days (heather article is not that easy to follow ) i find your article which is exactly i need
thanks for the article .but infact when i copy and paste code i get “Unable to display this Web Part. To troubleshoot the problem, open this Web page in a Windows SharePoint Services-compatible HTML editor suc” Please help i will really appreciate any assistance in this mater .
Thanks
Hey Omar, it’s probably some typo or something pointing to something unique that may not be available in your environment.
Thanks Mark and Henry
I replaced the βββ, ββ, and ββ¦β quotations and that didresolved some issues for me.
I have other issues where this line gives out an error :
This stuf i very tough to trooubleshoot also.
Also , when I add a specific GUID ( I got the guid from the URL of the posts) , I cannot really get that webpart ot disply also.
Also , why do you have two seperate guids for the same blog ?
It would be awesome if I can get this to work correctly…but I am seeing too many errors…
Hey man …the override with the list ID’s just doesnt work. I cannot even import the webpart with the list id. I realize you have tow list ID’s beause one is for the posts and other for the comments (How did you even get this list id). any help is appreciated.
Hey Z, in my example each GUID is for a different blog site’s document library that contains the posts. I haven’t tried using the CQWP for comments.
aah makes sense…thanks a lot !
I still am struggling with even adding this one line and not getting an error when I import the webpart. I wonder what I am doing wrong…..
:
<![CDATA[
]]>
I finally got it to work !!! thanks this is really helpful.
The user groupType is not defined as referenced below:
The corrected Template is below:
The user groupType is not defined as referenced below:<xsl:call-template name=βOuterTemplate.GetGroupNameβ><xsl:with-param name=βGroupNameβ select=β@Authorβ/><xsl:with-param name=βGroupTypeβ select=ββUserββ/></xsl:call-template>
The corrected Template is below:
<xsl:template name=”OuterTemplate.GetGroupName”> <xsl:param name=”GroupName”/> <xsl:param name=”GroupType”/> <xsl:choose> <xsl:when test=”string-length(normalize-space($GroupName)) = 0″> <xsl:value-of select=”$BlankGroup”/> </xsl:when> <xsl:otherwise> <xsl:choose> <xsl:when test=”$GroupType=’URL'”> <xsl:variable name=”Url”> <xsl:call-template name=”OuterTemplate.FormatValueIntoUrl”> <xsl:with-param name=”Value” select=”$GroupName”/> </xsl:call-template> </xsl:variable> <xsl:call-template name=”OuterTemplate.GetPageNameFromUrlRecursive”> <xsl:with-param name=”Url” select=”$Url”/> </xsl:call-template> </xsl:when> <xsl:when test=”$GroupType=’User'”> <xsl:value-of select=”substring-after($GroupName,’#’)”/> </xsl:when>
<xsl:otherwise> <xsl:value-of select=”$GroupName” /> </xsl:otherwise> </xsl:choose> </xsl:otherwise> </xsl:choose> </xsl:template>
Works great… BUT… the truncating of the Blog body field does not unfortunately leave “valid HTML”… with the result that if your blog posts contain any html formatting this will then “leak” out into the rest of the page.
I wish there were a way to access the functionality for the “summary view” for the list view web part. That somehow magically truncates any rich text – without any “leaking” problems.
I get this error:
List does not exist
The page you selected contains a list that does not exist. It may have been deleted by another user.
Troubleshoot issues with Windows SharePoint Services.
Hi Henry thanks for this post. But I still need a little of light over me
I’m getting the blog like it shows in the Step 3.
I’ve edited the 3 lines that you mention above but still not working π¦
My itemstyle portion code looks like this:
_blank
–
…
And the .webpart file was edited like follows:
Body, Description;
<![CDATA[ ]]>
ExternalUrl,URL;PublishingPageImage,Image;Body,Description;
Did you see anything wrong in my code?
I’m using Community Kit for SharePoint Blogs http://www.codeplex.com/CKS
Thanks in advance!!!
Ok, I make it works!!
I change a few things to try.
1st: I use @Body as internal name for the “Body” of the blog post in the .sxl file
2nd: I don’t rename the field on the “DataColumnRenames” property of my .wepbart file.
3rd: I use Body, RichHTML on the “CommonViewFields” property of my .webpart file.
The rest is the same as you use here.
I hope this helps.
Thanks… !!! π
Hi, I’m triyng to show the name of the blog for every blog post but I can’t find the way…
Does anybody know how to get the blog name??
Thanks
In the CQWP settings I open Presentation and group by . Is that what you are looking for?
I was wondering if it capable of seekingout all blogs on the server, or maybe the latest 20 posts from 20 different blogs automaticlly with out having to add the blogs to the web part..
What we are trying to do is have a blog aggregator that dynamiclly finds blogs created by staff and displays their posts in the aggregator rather than the sharepoint admins having to add a new blog everytime a new one is created.
ya Dan, you just point the Query Source to show all sites in the site collection, or if you want a specific site set it to show items from the following site and all subsites and browse to the level you want.
xlws utqlwba hmkuvone zcivsp atdyqb geqpd fozvlawxi
I’ve tried following the directions you’ve posted a bunch of times. Starting from scratch, reviewing and what not. I cannot for the life of me get the body of the blog posts to show up in the query. I get the title, date, author and the “…” link, but just no body of the blog post. It’s been quite frustrating so ANY insight to this would be very appreciated.
I added “Body, RichHTML” to the CommonViewFields property in the webpart file and created a custom item style in ItemStyle.xsl to show the Body of a blog post.
I could qute Toma:s post exactly, I can’t for the world get the description to show up. Any Ideas?
Nice Post!!
Except that it’s the same for as Toma and siss :.(
Keep trying…
Yes!! Did it like this:
ExternalUrl,URL;PublishingPageImage,Image;Body,Description;PublishingPageContent,RichHTML;
in the property name=CommonViewFields
Anthonyyy, I’ve tried with yours too, but it didn’t work as well. I’m at a loss.
Ok, I did end up getting this to work. With a combination of the other replies assistance.
I really am a newb when it comes to modifying the itemstyles, but I noticed, even in the example images posted above that the entries slowly indent as the number of blogs grows. I’m happy as hell that I finally got the posts to show, but if someone could help with some of the aesthetics I would be grateful!
I have tried what feels to be endless solutions to get this body text to display. I am at a complete loss as to why the value is not selected and displayed. Does anyone have some definitive answer as to how to get it to show up aside from the snippets in the comments?
ok henry this is for one site only
if i want get the blog posts from multiple subsites means how
Can someone please help me out with this. I’m getting all the way to step 4. My webpart will not display the teaser text for each of the blog entries. From reading all the replies I’m not really sure what to do at this point. People have said “I finally got it to work” but didn’t say what they are doing. Please help!
Got it to WORK!
I had to use Ariel’s advice and use @Body in the .xsl file to get it to work. We are in business.
Like to Thank Ariel too for the @Body tip that got it working for me too…
Great Post though thanks Henry.
unfortunately I cant post the template on here for people to use!
Content and Code developed a blog aggregation web part. Whcih is available from our website.
For those of you who still haven’t gotten this to work, try deleting the custom web part on your page and re-adding… For whatever reason, I had two of the same custom web part in my webpart gallery. I’m pretty sure I always had ‘Overwrite existing files’ checked when re-uploading.
Hi,
I tried all the stuff mentioned by you but failed at the Step-3. I tried replacing the “”‘ … ‘””(Copy paste) with “”‘ … ‘”” (manual written) but i am not able to resolve the issue.
Everytime i try doing some changes mentioned in the blog i landup with the erorr message…
“Unable to display this Web Part. To troubleshoot the problem, open this Web page in a Windows SharePoint Services-compatible HTML editor such as Microsoft Office SharePoint Designer. If the problem persists, contact your Web server administrator”
MB8Ar8 http://gdjI3b7VaWpU1m0dGpvjRrcu9Fk.com
Building backlinks is most important part of SEO. Web Directory submission can help webmaster to promote their websites by building backlinks, increasing exposure and traffic. Link Builder is a link building resource. You can list your website on search engine friendly and article directories to use as site promotion tools.
You can submit your link for free without registrer.
Argomento Matchless, Γ¨ molto interessante per me))))
Nice with XSL on blog site.
Quality articles is the crucial to be a focus for the users to pay
a visit the web page, that’s what this web page is providing.
Great post however , I was wondering if you could write a litte more on this subject?
I’d be very grateful if you could elaborate a little bit further. Bless you!
This piece of writing is actually a nice one it assists new internet people,
who are wishing in favor of blogging.
I drop a leave a response when I especially enjoy
a post on a site or if I have something to valuable to contribute to the discussion.
It’s caused by the fire displayed in the article I browsed.
And on this post How to customize the Content
Query Web Part XSL to aggregate blog posts | The SharePoint Swiss Army
Knife. I was excited enough to drop a thought ;
-) I do have some questions for you if it’s okay. Is it only me or
do a few of these responses look like left by
brain dead people? π And, if you are writing at other social
sites, I’d like to keep up with you. Could you
make a list the complete urls of your community sites like your twitter
feed, Facebook page or linkedin profile?
First of all I would like to say superb blog! I had a
quick question that I’d like to ask if you do
not mind. I was curious to know how you center yourself and clear your mind prior to writing.
I’ve had a hard time clearing my thoughts in getting my thoughts out there.
I truly do enjoy writing however it just seems like the first 10 to
15 minutes are wasted simply just trying to figure out how to begin.
Any suggestions or tips? Kudos!
Hi i am kavin, its my first time to commenting anyplace, when
i read this article i thought i could also create comment
due to this good post.
You will discover other beneficial rewards of listing a business on an internet enterprise web-site directory. As a result of advertising is often expensive for any business enterprise, substantial or small, listing with an online small business directory is really a expense efficient approach to publicize your enterprise. Listing can be relatively inexpensive, oftentimes about $5.00 to $10.00 a year. When listing within a conventional paper directory, after it is printed and distributed, it can’t be changed. A web based business directory allows you to modify and update your listing at any time.
Prior to deciding the package for low-priced hosting, it is actually smart to make an substantial search, as outlined by your requirements, their reputation, customer service, fees, and rules. If you expand the company they should really have the solution of expanding the hosting space or you need to switch more than to private server, as your business expands.
I know this if off topic but I’m looking into starting my own blog and
was curious what all is needed to get setup? I’m assuming having a blog
like yours would cost a pretty penny? I’m not very internet smart so I’m not 100% positive.
Any tips or advice would be greatly appreciated. Many thanks
Thank you a lot for sharing this with all folks you really recognise what you are talking
about! Bookmarked. Kindly also discuss with my site =).
We could have a hyperlink exchange agreement among us
I was able to find good advice from your blog posts.
Good post! We are linking to this great article on our website.
Keep up the good writing.
I have a notable analytical attention for fine detail and can
foresee difficulties just before these people occur.
Good day! I simply would like to give an enormous thumbs up for
the great data you have got here on this post. I will likely be coming back to your
blog for more soon.
reat publish, very informative. I woinder why the
opposite specialists of this secttor don’t notice this.
You should continue your writing. I am confident,
you’ve a great readers’ base already!