Textpattern tips, tutorials and code snippets

Archive by date and category

This is a follow up to a previous TXP Tip – Archive page with some style.

In this example, we create an Archive page that lists articles by date and categories. Here’s how to do it.

  1. Download the wonderful upm_date_archive plugin
  2. Install and activate the upm_date_archive plugin
  3. Once activated, visit the Extensions tab, and select the section that will display your archive – in our example it is archive

Place some code in your Archive page template

<div id="content">
<txp:if_individual_article>
<!-- individual page: display the full post -->
<txp:article form="single" limit="1" />
</txp:if_individual_article>
<txp:if_article_list>
<txp:if_category>
<txp:article form="article_list" limit=100 />
<txp:else />
<txp:article form="article_list_2" limit=100 />
</txp:if_category>
</txp:if_article_list>
</div>

The reason the forms are different within the if_category conditional tag is because the full article will be displayed if we are in a category page, if not, then display an article title. Here is the article_list_2 form:

<h3 class="clear"><txp:permlink><txp:title /></txp:permlink></h3>
<p class="post"><txp:posted /> <txp:if_article_category> &#149; Filed by <txp:author link="1" /> in <txp:category1 link="y" title="0" this_section="0" /> <txp:category2 link="y" title="0" this_section="0" />
</txp:if_article_category></p>
<p><txp:permlink>Read on...</txp:permlink><txp:if_comments_allowed> &#183; <txp:comments_invite wraptag="" /></txp:if_comments_allowed></p>

Archive menu

<h2>Archives</h2>
<h3>By Category</h3>
<txp:category_list section="archive" active_class="sidelink_active" break="li" class="sidelink" type="article" wraptag="ul" />
<h3>By Date</h3>
<txp:upm_date_menu id="archivemenu" link_to="archive" insert_empty_months="no" sort="the_year desc, the_month desc" month_format="%B" />

Place the above code where the archive menu should be placed. The category_list tag calls the categories, and displays the results in the archive page template.

The upm_date_menu tag calls all articles and sorts the results by date, then displays the results in the archive page template.

For more options, read the upm_date_archive plugin help. An example of this archive method is on this unfinished site.

Use Textile help to style your comments