Multiple teasers on one page, but without any duplicates

boesebeck
Crownpeak employee
Crownpeak employee
0 0 539

teaser1.pngA common request is to display several teasers on a page wihout any duplicates. How do I implement this? Use a global variable in the page context to store the already shown articles.

This page has 3 sections, each section can show several teasers for other articles. We only want to list teaser articles with a publish date greater than the specified date.

teaser2.png

The section template:

<CMS_HEADER>

<CMS_FUNCTION name="contentSelect" resultname="fr_article">
<CMS_PARAM  name="schema" value="knowledgebase" />
<CMS_VALUE_PARAM  name="from" value="publishdate" />
<QUERY entityType="article">
     <FILTERPARAM parameter="from" datatype="java.util.Date" value="1143758280000" />
     <GT attribute="publishdate" datatype="java.util.Date" parameter="from"/>
</QUERY>
</CMS_FUNCTION>
</CMS_HEADER>
<p><ul>
$-- Get the article list from the page context --$
$CMS_SET(listedArticles, #global.pageContext.getVariableValue("listedArticles"))$
$CMS_SET(count, 0)$
$CMS_FOR(article, fr_article)$
   $CMS_IF(count <= maxcount -1 && !listedArticles.contains(article.id))$
     <li>$CMS_VALUE(article.teaserList.get(0).title)$</li>
     $-- add given article to the list --$
     $CMS_SET(void, listedArticles.add(article.id))$
     $CMS_SET(count, count + 1)$
   $CMS_END_IF$
$CMS_END_FOR$
$-- Write article list back in the page context --$
$CMS_SET(void,#global.pageContext.setVariableValue("listedArticles" , listedArticles))$
</ul><p>
Version history
Last update:
‎07-01-2010 10:40 AM
Updated by: