Archive using parent and children categories

Using categories to organise your site’s content is a great way to take advantage of the great CMS that is Textpattern.

In this example, the idea was to make it simple for a client to move old content to their archive, which is organised and presented by year.

Because we do not know in advance the names of the categories that the client will choose, we start by creating a parent article category called News Archive.

The category_list menu item

<h2>Categories</h2>
<txp:category_list break="li" class="height200" exclude="News Archive" parent="News Archive" section="archive" type="article" wraptag="ul" />

The above code should be placed in your page template. We are using the category_list tag to create the list of article categories.

To explain the tag usage – the parent="News Archive" is set to News Archive, the category we created earlier. This attribute will return only the News Archive category and its “child” categories. The next important attribute is exclude="News Archive". This excludes News Archive itself, but will return all child categories of News Archive.

Make it easy for the user/client

The client may now create categories under News Archive, and they will be displayed automatically. Then, thanks to Textpattern’s easy content management, the client only has to visit the Articles tab to move old content to the new child category.

Displaying the content

<txp:if_category>
<h2><txp:category /></h2>
<ul>
<txp:article_custom limit="99999" form="news_archive_list" section="archive" category='<txp:category />' />
</ul>
<txp:else />
<txp:if_individual_article>
<txp:article limit="1" />
<txp:else/>
<h2>News Archive</h2>
<ul>
<txp:article_custom limit="99999" form="news_archive_list" section="archive" />
</ul>
</txp:if_individual_article>
</txp:if_category>

We place this code in our page template. Note that it requires the use of Textpattern 4.07, due to the use of category='<txp:category />' in the article_custom call.

The news_archive_list form

<!-- show the year and month -->
<txp:if_different>
<h3><txp:posted format="%B %Y" /></h3>
</txp:if_different>
<!-- article title and link -->
<li class="links"><txp:permlink><txp:title /></txp:permlink></li>

And there you have it, an easy way for your clients or users to organise their content without needing any intervention from the site developer.

Thanks to Luis Flores for asking for this tip.

An example of this method may be viewed here – the category list is on the right side of the page.

comments powered by Disqus