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

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;       ...

SQL SPLIT FUNCTION or String_split sql function alternative Very Information (Solved)

Dear All,  Today i created a form with the checkbox list and store the value in the sql with comma seprated way. It was strange for me that the split_string function is not supported in sql 2014, so i have created split function that will help to split the comma sepearted values   CREATE FUNCTION dbo.Split(@String varchar(8000), @Delimiter char(1))      returns @temptable TABLE (items varchar(8000))      as      begin      declare @idx int      declare @slice varchar(8000)      select @idx = 1          if len(@String)<1 or @String is null  return      while @idx!= 0      begin          set @idx = charindex(@Delimiter,@String)          if @idx!=0              set @slice = left(@String,@idx - 1)          else  ...