Displaying Fields in Content Query WebParts

Following my earlier post today, I explained how you can customise your CQWP.

I had a series of articles which I wanted to see the article date and who the publishing contact person was, not the author as the author could be an admin person. So how did I get this done, with patience and lots of Googling!

First, create the query and export to your desktop, open with notepad and amend the property CommonViewFields. For my own use, I needed the article date, not modified and the contact name. I had originally set the contact name as text, that is wrong, it should be a LookUp as contact names are entered using a people picker in the original article page.

<property name=”CommonViewFields” type=”string”>ArticleStartDate,DateTime;PublishingContact,Lookup</property>

Next step is to amend the itemstyle.xsl.

Add   xmlns:ddwrt=”http://schemas.microsoft.com/WebParts/v2/DataView/runtime” to the header so that the date is passed through.

I copied the first template and renamed the name (as per Microsoft blog).

First, define the variable for the PublishingContent element.

<xsl:variable name=”PublishingContact”>
       <xsl:call-template name=”OuterTemplate.GetGroupName”>
           <xsl:with-param name=”GroupName” select=”@PublishingContact”/>
           <xsl:with-param name=”GroupType” select=”‘PublishingContact'”/>

In the first   <div class=”description”>, you have to declare what you want the content web part to display. The script is:

<xsl:value-of select=”ddwrt:FormatDateTime(string(@ArticleStartDate) ,1033 ,’d/M/yyyy’)” />
Created by – <xsl:value-of select=”$PublishingContact”>

Make sure you check in the file as a minor and preview your changes on your web page. . all should be fine.

Hope this helps someone!!


Tags: , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: