Using CQWP To Show Discussion Rollup with Reply Count and Last Update Date

This is what we want our final result to look like:

DiscussionRollupFinal

1) Add a Content Query Web Part to your page.  Go in and expand the “Query” section.  Modify it to show just the discussions for your site.  Then click OK.  Verify that you can see your discussions.

DiscussionRollupStep1

2) This is where things get a little tricky.  You will need to access the ItemStyle.xsl file of your site, and modify it by adding a new template within the file.  Just find a spot where the templates are within that file and copy and paste the following template entry (be sure to keep what you already have in that file):

<xsl:template name="DiscussionAndReplies" match="Row[@Style='DiscussionAndReplies']" mode="itemstyle">
 <xsl:variable name="vv1"> 
 <xsl:value-of select="@LinkUrl"/> 
 </xsl:variable>
 <xsl:variable name="formattedLastUpdatedDate">
 <xsl:value-of select="ddwrt:FormatDateTime(string(@DiscussionLastUpdated) ,1033 ,'dd MMM yyyy')" />
 </xsl:variable>
 <xsl:variable name="listTitleEnd">
 <xsl:call-template name="substring-before-last">
 <xsl:with-param name="list" select="@LinkUrl" />
 <xsl:with-param name="delimiter" select="'/'" />
 </xsl:call-template>
 </xsl:variable>
 <xsl:variable name="listTitle">
 <xsl:call-template name="substring-after-last">
 <xsl:with-param name="string" select="$listTitleEnd" />
 <xsl:with-param name="delimiter" select="'/'" />
 </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>
 <div class="item link-item">
 <a href="{$vv1}" target="{$LinkTarget}" title="{@LinkToolTip}"> 
 [<xsl:value-of select="$listTitle" />] <xsl:value-of select="$DisplayTitle"/> - Replies:(<xsl:value-of select="substring-after(@ItemChildCount,'#') "/>) - Last updated: <xsl:value-of select="$formattedLastUpdatedDate" />
 </a>
 </div>
</xsl:template>

3) Once you’ve done that, go back and edit your Content Query Web Part.  Now, scroll down to “Presentation” and expand it.  Be sure to select the sorting / counts you’d like displayed.  Then be sure to select your new style template you just added.

DiscussionRollupStep2

5) If you are using SharePoint 2013, you will want to make sure you add the entry for the ItemChildCount, as it will not be picked up automatically.  (I spent a good couple hours trying to figure out why it would display in SP2010 and not SP2013.)

DiscussionRollupStep3

6) Click ok, and voila!  A nice rollup of a more detailed view of the discussion content on your site.

DiscussionRollupFinal

Posted in SharePoint 2010, SharePoint 2013.

One Comment

  1. Hi Josh,

    I cannot have the behaviour than you…
    How do you add parameters in the .webpart ItemChildCount and LastUpdated into the toolparteditor ?
    I updated DataMappings but it’s ok…
    Can you help me please ?

    Julien

Leave a Reply

Your email address will not be published. Required fields are marked *