Textpattern tips, tutorials and code snippets

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_article_list>
        <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" />
        </txp:if_category>
    </txp:if_article_list>
</txp:if_section>

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="">
        <txp:if_first_category>
            <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>
        </txp:if_first_category>
    </txp:category_list>
</txp:if_section>

2 Comments Comment feed

Together we are strong … :)

Great post!

I can’t help but think wish that a really “hands-on” book on Textpattern would be written. The one that I bought a few years back “Textpattern Solutions” missed the mark.

In the meantime really appreciate these TxP Tips

Add a comment

Use Textile help to style your comments