文章的分类要是思路:
在文章结构中添加一个字段,最好是下拉列表来代表你要发布文章的是属于哪个分类,这样在模板中#if( $category.getText() == "one")用于判断要显示的是哪个分类的文章。代码经过测试可以放心使用
webpublish要解决如下问题
结构:主要定义一个下拉列表用于给文章指定分类
<root available-locales="en_US" default-locale="en_US">
<dynamic-element dataType="string" indexType="keyword" name="content" readOnly="false" repeatable="false" required="false" showLabel="true" type="text" width="small">
<meta-data locale="en_US">
<entry name="label">
<![CDATA[content]]>
</entry>
<entry name="predefinedValue">
<![CDATA[]]>
</entry>
<entry name="tip">
<![CDATA[]]>
</entry>
</meta-data>
</dynamic-element>
<dynamic-element dataType="string" indexType="keyword" multiple="false" name="categoryValue" readOnly="false" repeatable="false" required="false" showLabel="true" type="select" width="">
<dynamic-element name="option6462" type="option" value="one">
<meta-data locale="en_US">
<entry name="label">
<![CDATA[nwes2新闻]]>
</entry>
</meta-data>
</dynamic-element>
<dynamic-element name="option6463" type="option" value="two">
<meta-data locale="en_US">
<entry name="label">
<![CDATA[new1新闻]]>
</entry>
</meta-data>
</dynamic-element>
<meta-data locale="en_US">
<entry name="label">
<![CDATA[categoryValue]]>
</entry>
<entry name="predefinedValue">
<![CDATA[[""]]]>
</entry>
<entry name="tip">
<![CDATA[]]>
</entry>
</meta-data>
</dynamic-element>
</root>
模板:用于判断到底显示属于哪个分类下的文章
news1新闻
#if (!$entries.isEmpty())
#foreach ($curEntry in $entries)
#set ($renderer = $curEntry.getAssetRenderer())
#set ($article = $renderer.getArticle())
<input type="hidden" value="$article.getArticleId()">
#set ($document = $saxReaderUtil.read($article.getContentByLocale($locale.toString())))
#set( $category = $document.selectSingleNode("/root/dynamic-element[@name='categoryValue']/dynamic-content"))
#set ($content = $document.selectSingleNode("/root/dynamic-element[@name='content']/dynamic-content"))
#set ($curtitle = $article.getTitle($locale))
#if( $category.getText() == "one")
$category.getText()
$curtitle
$content.getText()
#end
#end
#end
---------------
news2新闻
#if (!$entries.isEmpty())
#foreach ($curEntry in $entries)
#set ($renderer = $curEntry.getAssetRenderer())
#set ($article = $renderer.getArticle())
<input type="hidden" value="$article.getArticleId()">
#set ($document = $saxReaderUtil.read($article.getContentByLocale($locale.toString())))
#set( $category = $document.selectSingleNode("/root/dynamic-element[@name='categoryValue']/dynamic-content"))
#set ($content = $document.selectSingleNode("/root/dynamic-element[@name='content']/dynamic-content"))
#set ($curtitle = $article.getTitle($locale))
#if( $category.getText() == "two")
$category.getText()
$curtitle
$content.getText()
#end
#end
#end
添加文章:选择合适的分类即可