Textpattern tips, tutorials and code snippets

Display a linklist category title if links exist

Here is a solution to a small problem I was having today – how to display a list of category titles only if there are links within that category. Example:

Cat 1 title

  • link 1
  • link 2

Cat 2 title

  • link 3
  • link 4

… and so on.

The code

<txp:category_list type="link" break="">
	<txp:variable name="link_list"><txp:linklist category='<txp:category />' /></txp:variable>
	<txp:if_variable name="link_list" value="">
		<txp:else />
		<h3><txp:category type="link" title="1" /></h3>
			<div class="link_entry">
				<txp:linklist category='<txp:category />'>
					<p><txp:link /><br /><txp:link_description /></p>
				</txp:linklist>
			</div>
	</txp:if_variable>	
</txp:category_list>

Thanks to Dragondz and jakob for helping find a solution.

Use Textile help to style your comments