First, I clarify that custom fields have existed in list or library. They are difference from custom field control.
Why we should display custom fields in content by query web part, because of only one column can be displayed when we use CQWP.
By default, the XSL style sheet that controls the presentation of the Content By Query Web Part renders the Title, Description, ImageUrl, and LinkUrl columns (if present) of the items that the query returns. The Web Part renders the ImageUrl column and the LinkUrl column as an image and as a hyperlink, respectively. The Content By Query Web Part uses XSL style sheets to render these columns by default.
first:Export content query web part.you can export from page or web part gallary.
Second:
CQWP is actually xml file.You can edit it by VS, Sharepoint Designer or XML Editor Tools.
Third:
So,if you dont want to modify default xslt,you should
<property name="CommonViewFields" type="string">KB_x0020_Title,Text;Product,Text;</property>
note:KB_x0020_Title is internal column name,Text is field type.
<property name="DataColumnRenames" type="string">KB_x0020_Title,Title;Product,Description</property>
注意: |
你不能使用你的栏本身的名称而应该使用内部名称。你可以通过右击这个栏然后选“属性”,然后在浏览器的“地址”一栏,你可以找到”Field=”这个字串,后面就是这个栏的内部名称。本示例中的“知识库文章标题”和“产品”的内部名称就是:KB_X0020_Title和Product。 |
注意: |
默认的XSLT转换可以渲染如下四个字段:标题、说明、URL超链、图片URL。在你的DataColumnRenames属性,确认你指定了相符的XSLT转换名称:Title,Description,LinkUrl,ImageUrl。 |
Fourth:
Upload this webpart into Webpart Gallay or Import this webpart when you edit page.
Content Query Web Part is only display one column by default.
Sample Two:
we only should modified step three,we can copy one template.
<
xsl:template name = " AA " match = " Row[@Style='AA'] " 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 = " 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 id = " linkitem " class = " item link-item "
>
<
xsl:call-template name = " OuterTemplate.CallPresenceStatusIconTemplate "
/>
<
table
>
<
tr
>
<
xsl:if test = " position() mod 2 = 1 "
>
<
xsl:attribute name = " class " > ms-alternating </ xsl:attribute
>
</
xsl:if
>
<
td class = " ms-vb " rowspan = " 3 "
>
<
img border = " 0 " src = " {@Img} "
/>
</
td
>
<
td class = " ms-vb "
>
<
a href = " {$SafeLinkUrl} " target = " {$LinkTarget} " title = " {@LinkToolTip} "
>
<
xsl:value-of select = " $DisplayTitle "
/>
</
a
>
</
td
>
</
tr
>
<
tr
>
<
td
>
<
xsl:value-of select = " @Desp "
/>
</
td
>
</
tr
>
<
tr
>
<
td
>
<
xsl:value-of select = " ddwrt:FormatDate(string(@Modified) ,1033 ,3) "
/>
</
td
>
</
tr
>
</
table
>
</
div
>
</
xsl:template
>
Note:Because we used ddwrt,so we should import the namespace of this in itemstylecustom.xsl.
<
xsl:stylesheet
version = " 1.0 "
exclude-result-prefixes = " x d xsl msxsl cmswrt
"
xmlns:x = " http://www.w3.org/2001/XMLSchema "
xmlns:d = " http://schemas.microsoft.com/sharepoint/dsp "
xmlns:cmswrt = " http://schemas.microsoft.com/WebParts/v3/Publishing/runtime
"
xmlns:xsl = " http://www.w3.org/1999/XSL/Transform " xmlns:msxsl = " urn:schemas-microsoft-com:xslt
"
xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime"
>
References:
http://msdn.microsoft.com/en-us/library/bb850574(office.12).aspx
http://msdn.microsoft.com/en-us/library/bb850574(office.12).aspx
http://www.cnblogs.com/ceci/archive/2009/07/31/1536014.html
http://www.cnblogs.com/dosboy/archive/2008/05/07/1186104.html