How do I make an archive of articles grouped by month?
How do I show a list of all articles?


(This technique requires Textpattern 4.0.2+)

Here’s a step-by-step method for creating a page that lists all articles with headings for each month (or year):

1. Create a new article form (presentation > forms). Call it monthly_article:

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

2. Copy an existing page template (such as default) to a new one named archive_list.

3. Edit the archive_list template. In the main content block, replace the <txp:article /> tag with this:

<txp:article_custom limit=99999 form="monthly_article" />

4. Create a section named archive, list, or similar. The section page ( or will be used to display the list of articles. Select archive_list as the page template (“Uses page:”).


The monthly_article form above will display the year and month separately. You can combine them together like this:

<txp:if_different><h3><txp:posted format="%B %Y" /></h3></txp:if_different>

The format string can include any of the format specifiers supported by PHP’s strftime function. (Beware, Windows doesn’t support all of those). <txp:if_different> only displays its enclosed content when that content changes.

To include an excerpt, timestamp, category name or other information with each article link, simply use the appropriate article form tags in the monthly_article form.

To display the articles in an unordered list, use a li tag in the monthly_article form:

<txp:permlink><txp:title /></txp:title>

..and, in the archive_list page template, wrap the article_custom tag in a ul:

<ul><txp:article_custom limit=99999 form="monthly_article" /></ul>

To display only articles from a specific section or category, change the article_custom tag:

<txp:article_custom limit=99999 form="monthly_article" section="products" />


<txp:article_custom limit=99999 form="monthly_article" category="weather" />

To group articles by something other than date, such as section, create a form named section_article:

<!-- show the section -->
<h2><txp:section title=1 /></h2>
<!-- article title and link -->
<txp:permlink><txp:title /></txp:title>
<br />

And change the article_custom tag to sort by section:

<txp:article_custom limit=99999 form="section_article" sortby="section" />