List articles from a specific category on a landing page

Here is a simple tip for having a section landing page that only lists articles in a specific category (as requested in this forum thread). The section in question is a list of employees, and the categories are departments. The section landing page should only display employees listed under staff.

This implies that in the category menu in the sidebar not only the currently viewed category, but also the ‘staff’ category when on the section landing page, should have an active class.

The base code

The code for the article list is fairly simple:

<txp:if_section name="employees">
        <txp:if_category name="staff,dept2,dept3,dept4">
            <!-- one of the category pages -->
            <txp:article form="yourform" />
        <txp:else />
            <!-- section landing page -->
            <txp:article_custom section='<txp:section />' category="staff" form="yourform" />

The sidebar menu

In this case the ‘staff’ category is the first one in the category list, which makes coding the sidebar menu not too hard:

<txp:if_section name="employees">
    <txp:category_list categories="staff,dept2,dept3,dept4" wraptag="ul" break="">
            <li<txp:if_category name='<txp:category />'> class="active"<txp:else /><txp:if_category><txp:else /><txp:if_article_list> class="active"</txp:if_article_list></txp:if_category></txp:if_category>><txp:category title="1" link="1" this_section="1" /></li>
        <txp:else />
            <li<txp:if_category name='<txp:category />'> class="active"</txp:if_category>><txp:category title="1" link="1" this_section="1" /></li>
comments powered by Disqus