SharePoint Content Query Web Part Custom Header and Footer

SharePoint Content Query Web Part Custom Header and Footer

Ever wanted to add custom headers and footers in the Content Query Web Part? Here is a quick sample of how to add both. Thanks to Zac Orndorff for figuring this out. 

Use this in an itemstyle to output a header:

<xsl:if test="count(preceding-sibling::*)=0">
</xsl:if>

Use this in an itemstyle to output a footer:

<xsl:if test="count(following-sibling::*)=0">
</xsl:if>

A Sample Item Style

  <xsl:template name="HeaderFooter" match="Row[@Style='HeaderFooter']" 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>
        <!-- header -->
        <xsl:if test="count(preceding-sibling::*)=0">
<div class="header">
<div class="header-row">
<div class="header-column title">Title</div>
<div class="header-column description">Description</div>
</div>
</div>
</xsl:if>
        <!-- end header -->
        <div class="item">
           <div class="link-item">
              <xsl:call-template name="OuterTemplate.CallPresenceStatusIconTemplate"/>
                <a href="{$SafeLinkUrl}" title="{@LinkToolTip}">
                  <xsl:if test="$ItemsHaveStreams = 'True'">
                    <xsl:attribute name="onclick">
                      <xsl:value-of select="@OnClickForWebRendering"/>
                    </xsl:attribute>
                  </xsl:if>
                  <xsl:if test="$ItemsHaveStreams != 'True' and @OpenInNewWindow = 'True'">
                    <xsl:attribute name="onclick">
                      <xsl:value-of disable-output-escaping="yes" select="$OnClickTargetAttribute"/>
                    </xsl:attribute>
                  </xsl:if>
                  <xsl:value-of select="$DisplayTitle"/>
                </a>
                <div class="description">
                    <xsl:value-of select="@Description" />
                </div>
            </div>
        </div>
        <!-- footer -->
<xsl:if test="count(following-sibling::*)=0">
<div class="footer-row">
<div class="footer-column view-all">
<a href="#">View All Items</a>
</div>
</div>
</xsl:if>      
<!-- end footer -->  
    </xsl:template>

Some CSS to clean up the display:
.header-row, .footer-row {

background: url("/_layouts/images/selbg.png") repeat-x left top;
background-color: #F6F6F6;
vertical-align: middle;
min-height: 25px;
border-top: 1px solid #E0E0E0;
border-bottom: 1px solid #B8BABD;
border-left: 1px solid #E0E0E0;
border-right: 1px solid #B8BABD;
}
.header-column, .footer-column {
display: inline-block;
padding: 0.5em 2.2em 0.5em 0.5em;
min-width:200px;
}
.item {
border-left: 1px solid #E0E0E0;
border-right: 1px solid #B8BABD;
}
.footer-column.view-all {
text-align:center;
width:100%;
}

Author

Staff

Founder

Send a Message