New icon to CQWP – Content Query Webpart

Hi,

So you may have wondered HOW to enable or add a new icon to a CQWP. Well aparently you can not do it through the user interface and you need to do some XSLT modifications. Here is what you need to do:

1. You need to download the following MS XSL file to datetime processing and add it into your XSLT file that displays your data:

The MS BLOG file

The XSL piece of code to add your XSL file, this will include the above downloaded file into your XSL file:

<xsl:import href=”/Style Library/XSL Style Sheets/date_templates.xsl”/>

2. Inside your XSL file that displays data(in the case of a CQWP lets say the item style XSL template) add the following lines:

<xsl:call-template name=”getDayDelta”>
<xsl:with-param name=”paramDateA” select=”@ArticleDate”/>
<xsl:with-param name=”paramDateB” select=”ddwrt:Today()”/>
</xsl:call-template>

<xsl:variable name=”article_date”>
<xsl:value-of select=”ddwrt:FormatDate(string(@ArticleStartDate), 1033,1 )”/>
</xsl:variable>
<xsl:variable name=”today”>
<xsl:value-of select=”ddwrt:FormatDate(string(ddwrt:Today()), 1033, 1)”/>
</xsl:variable>
<xsl:variable name=”date_diff”>
<xsl:call-template name=”getDayDelta”>
<xsl:with-param name=”paramDateB” select=”ddwrt:FormatDateTime(string(@PublishedDate),1033, ‘yyyy-MM-dd’)”/>
<xsl:with-param name=”paramDateA” select=”ddwrt:FormatDateTime(string(ddwrt:Today()),1033, ‘yyyy-MM-dd’)”/>
</xsl:call-template>
</xsl:variable>

The above was meant for a CQWP that would lift the latest blogs inside a blog site. Notice the @PublishedDate parameter. This can be @ArticleDate or @ArticleStartDate etc. What you need to make the date difference calculations.

The date_diff XSL variable will hold the date time calculation between the blog post published date and the present date. Then you can use this value to determine when to show the New icon.

3. Add the logic to display the New icon. The below logic tells that if the items is less than 7 days old you need to display the New icon.

<xsl:if test=”$date_diff &lt; 7″>
<img src=”/_layouts/1033/images/new.gif” alt=”New!” />
</xsl:if>

Sample in the XSL Blog title:

<div class=”blogListPostBlock”>
<!– Title –>
<h4>
<a style=”color: #295AC6;”>
<xsl:attribute name=”href”>
<xsl:value-of select=”$SafeLinkUrl”/>
</xsl:attribute>
<xsl:value-of select=”$DisplayTitle” />
<xsl:if test=”$date_diff &lt; 7″>
<img src=”/_layouts/1033/images/new.gif” alt=”Smiley face” />
</xsl:if>
</a>
</h4>

Also please take into consideration that this is for the LCID language ID 1033 English  You need to make sure it fits your language if you wish to use a different language translation for New icon.

Advertisements

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s