Textpattern tips, tutorials and code snippets

Archive page in an article

In some instances you may need an archive page with a URL like so: domain.com/articles/archive. As Textpattern does not support sub-sections, your current options are:

  1. Use categories (works but the URL is not clean)
  2. Use a plugin such as gbp_permanent_links (requires extra work and maintenance)
  3. Use an article (we get the URL, but code needs to be placed in the article)

In this tip, we’ll try the third method.

Create your article

Create an article named archive in the section of your choice. For the sake of this example, it would be the articles section.

Add some code to your article

<ul>
<li><txp:link_to_home>Home</txp:link_to_home></li>
<txp:section_list sections="section-5,section-1,section-2,section-7" break="">
<li><txp:section title="1" />
<txp:article_custom section='<txp:section />'>
<txp:if_first_article><ul></txp:if_first_article>
<li><a href="<txp:permlink />" title="<txp:title />"><txp:title /></a></li>
<txp:if_last_article></ul></txp:if_last_article>
</txp:article_custom>
</li>
</txp:section_list>
</ul>

Replace the sections attribute with your preferred section(s). The break="" is necessary or section_list will output <br /> tags.

The <txp:article_custom section='<txp:section />'> returns articles from the list of sections defined in the section_list tag: <txp:section_list sections="section-5,section-1,section-2,section-7">.

Turn off Textile or add spaces

Don’t forget that Textile will add <p> tags to the code block. To stop this from happening, either add a space before the start of the code block or turn Textile off for this article.

There you have it, a simple Archive page with a nice URL that resembles a sub-section.

Use Textile help to style your comments