List related links from categories and sections

I wanted a list of 10 links in each page, populated with related links (same category and section) and augmented with links from the same section, omiting any duplicate entries.

The solution was proposed by Jakob and Uli.

<txp:variable name="relatedtexts" 
	value='<txp:related_articles limit="10" break=",">
		<txp:article_id />
<txp:variable name="moretexts" 
		limit="10" section=''<txp:section />'' 
		break="," sort="rand()">
	<txp:article_id />
	</txp:article_custom>' />

<txp:if_variable name="relatedtexts" value="">
<txp:article_custom limit="10" section='<txp:section />' break="li" wraptag="ul" sort="rand()" class="related_articles"><txp:permlink><txp:title /></txp:permlink></txp:article_custom>
<txp:else />

	id='<txp:rah_repeat offset="1" 
	break="," duplicates="1" 
	sort="regular asc" 
		value=''<txp:variable name="relatedtexts"/>,<txp:variable name="moretexts" />''>
		<txp:rah_repeat_value />
		sort='field(ID,<txp:variable name="relatedtexts" />,<txp:variable name="moretexts" />)'>
  <txp:permlink><txp:title /></txp:permlink>

The above code produces a linked list:

  • related link 1
  • related link 2
  • related link n
  • same section link n+1
  • same section link n+2
  • same section link 10

For further information, see the related forum thread.

comments powered by Disqus