Display section sensitive articles and category title

Here is a method of fetching articles along with the category title if an article exists in the current section. Perfect for displaying a list of articles for your sidebar.

The code will not require any updating over time. First we check if there are any articles in the current section and assigned to a category.

If there are no articles, nothing is displayed. If articles do exist, the code after <txp:else /> is executed.

The code

   <txp:variable name="has_articles" value='<txp:article_custom section=''<txp:section />'' category=''<txp:category />'' limit="1" />' />
   <txp:if_variable name="has_articles" value="">
   <txp:else />
   <div class="module">
   <h4><txp:category title="1" /></h4>
   <txp:article_custom section='<txp:section />' category='<txp:category />' wraptag="ul" class="listing" break="li">
   <txp:permlink><txp:title /></txp:permlink>

Sample page

This code may be seen on the following Code sample page – right sidebar.

comments powered by Disqus