Skip to main content

Content Query Webpart Template In SharePoint 2013 and add new column in it

Dear All,
Here is the easiest way to make add custom column under your content query web part and then you can format it as you want.

Step 1: 
Open Sharepoint design

Step 2: 
Open site for sharepoint parent site collection

Step 3: 
Locate the following folder
Style Library > XLS Style Sheets

Step 4: 
Open "ItemStyle.xsl" file

Add the custom style sheet as you want




<xsl:template name="[Your Style Name]" match="Row[@Style='[Your Style Name]']" mode="itemstyle">
                                                  <xsl:param name="CurPos" />
                                                    <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>
Here you define your custom column input
                                                 <xsl:variable name="[Your Column Variable Name]">
                                                         <xsl:value-of select="@[Your Column Variable Name]" />
                                                </xsl:variable>
Here you Call this under your template                                                                 
                                                <xsl:value-of select="$[Your Column Variable Name]"></xsl:value-of>
                                                                               

</xsl:template>

If you need to add any HTML between these tags you can like 

<div class="[Your Class Name"]> 
   <xsl:value-of select="$[Your Column Variable Name]"></xsl:value-of>
</div>

I hope it will save your time


Just for reference i am putting the complete template below

<xsl:template name="NewsPagelist" match="Row[@Style='NewsPagelist']" mode="itemstyle">
                                                  <xsl:param name="CurPos" />
                                                    <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="ArticleDate">
                                                     <!--
                                                                <xsl:value-of select="ddwrt:FormatDateTime(string($ArticleDate), 1025, 'MMMM dd, yyyy')" />
                                                                <xsl:value-of select="@ArticleDate" />
                                                                <xsl:value-of select="ddwrt:FormatDateTime(string($ArticleDate) ,1025 ,'yyyy/MM/dd')" />
                                                                                !-->
                                                                <xsl:value-of select="@ArticleDate" />
               
                                                  
                                               
                                               
                                                </xsl:variable>
                                                                <xsl:variable name="NewsDescription">
                                                <xsl:value-of select="@NewsDescription" />
                                                </xsl:variable>
                                                                <xsl:variable name="NewsCategory">
                                                <xsl:value-of select="@NewsCategory" />
                                                </xsl:variable>

                                                  <div id="newsitem">
                                                <div id="newsimage">
                                                                                                <a style="color: rgb(0, 0, 0); text-decoration: none;" href="{$SafeLinkUrl}">
                                                                                                <img style="border: currentColor; border-style:none;" width="140px" height="140px" alt="" src="{$SafeImageUrl}"></img>
                                                                                                </a>
                                                </div>
                                                                               
                                                 <div id="newsDetail">
                                                                               
                                                                                <div id="newstitle">
                                                                                <a  href="{$SafeLinkUrl}">
                                                                                      <xsl:value-of select="$DisplayTitle"/>
                                                                     </a>

                                                                                               
                                                </div>
                <div id="newsDescription">
                                                                                                <xsl:value-of select="$NewsDescription"></xsl:value-of>
                                                                                  </div>
                                                                                <div id="newsInfo">
                                <div id="newsdate">
                                  <!--
                                                                  <xsl:value-of select="$ArticleDate"/>
                                                                 !-->
                                                                                  <xsl:value-of select="ddwrt:FormatDateTime(string($ArticleDate), 1033, 'MMMM dd, yyyy')" />
                                                                               
                                                                                  </div>
                                                <div id="newscategory">
                                                                                               <xsl:value-of select="$NewsCategory">
                                                                                               </xsl:value-of>
                                                </div>
                                                                                <div id="newsmore">
                                                                                <a  href="{$SafeLinkUrl}">
                                                                                <img src="/ar-sa/PublishingImages/GACA-ES-In_17.gif" alt=""></img>
                                                                                </a>
                                                                                </div>
                                                                                </div>
                                                                               
                                                                                </div>
                                                               
                                                </div>
                                                  <center style="clear:both">
              <xsl:if test="$PageSize &gt; 0">
                  <xsl:variable name="NumPages" select="ceiling($TotalRecords div $PageSize)"/>
              <xsl:if test="$NumPages &gt; 1">
                  <xsl:variable name="PageBeforeLast" select="$NumPages - 1"></xsl:variable>
                  <xsl:variable name="CountBeforeLastPage" select="$PageBeforeLast * $PageSize"></xsl:variable>
                  <xsl:variable name="LastPageCount" select="$TotalRecords - $CountBeforeLastPage"></xsl:variable>
                      <xsl:if test="$PageNumber = $NumPages and $CurPos = $LastPageCount">
                            <br/>
                            <xsl:call-template name="PagingControls-AR">
                              <xsl:with-param name="Page" select="1" />
                              <xsl:with-param name="NumPages" select="$NumPages" />
                            </xsl:call-template>
                      </xsl:if>
                      <xsl:if test="$CurPos = $PageSize and $NumPages &gt; 1 and $PageNumber != $NumPages">
                        <br/>
                        <xsl:call-template name="PagingControls-AR">
                          <xsl:with-param name="Page" select="1" />
                          <xsl:with-param name="NumPages" select="$NumPages" />
                        </xsl:call-template>
                  </xsl:if>
                  </xsl:if>
              </xsl:if>
            </center>

                               

</xsl:template>



Regards 
Rashid Imran Bilgrami 

Comments

  1. 81

    Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a .Net developer learn from Dot Net Online Training from India. or learn thru ASP.NET Essential Training Online . Nowadays Dot Net has tons of job opportunities on various vertical industry.
    JavaScript Online Training from India

    ReplyDelete

Post a Comment

Popular posts from this blog

SharePoint: A Complete Guide to Getting and Setting Fields using C#

Original article https://social.technet.microsoft.com/wiki/contents/articles/21801.sharepoint-a-complete-guide-to-getting-and-setting-fields-using-c.aspx Introduction This article demonstrates how to set and get the various SPField types for a SharePoint list using C#. The examples demonstrated set and get fields from an item that belongs to a custom list. The custom list contains a number of fields, and all the fields are named based on the type of field they are. For example, there is a Text field, which has been named, textfield. This is depicted in the following picture:   Applies To The examples demonstrated below are tested with and apply to the following versions of SharePoint: SharePoint 2010 SharePoint 2013 Get the List, and the first SPListItem This is the basic code for getting an item. If the list has at least one item, the first item is retrieved, otherwise a new item is created. var web = SPContext.Current.Site.RootWeb; var list = web.Lists.Try

Updatepanel or Enable Ajax in SharePoint webpart

Dear All It is really giving me a hard to get this techniques if you want to run the update panel in sharepoint 2013 webpart then you need to initialize the script manage by code   protected override void OnInit(EventArgs e)         {             base.OnInit(e);             InitializeControl();             // Register the ScriptManager             ScriptManager scriptManager = ScriptManager.GetCurrent(this.Page);             if (scriptManager == null)             {                 scriptManager = new ScriptManager();                 scriptManager.ID = "ScriptManager1";                 scriptManager.EnablePartialRendering = true;                 Controls.AddAt(0, scriptManager);             }         } In ascx page you need to add the following  <asp:UpdateProgress ID="UpdateProgress1" runat="server">     <ProgressTemplate>         <h1>Your progress value</h1>     </ProgressTemplate> </asp:U