Create an Archive Page with TXP

08/24 '09

Since it wasn’t possible to use valid nested lists for the markup, I updated the code to use a definition list instead.

Using the power of <txp:if_different> you can create a very powerful article archive page in Textpattern. The goal of this 3 step process is to create an article archive page that organizes the articles by year and then month, all without using a plugin.

Step 1: Create an Archive List Form

Form Name: archive.list

<txp:if_different>
  <dt class="year"><txp:posted format="%Y" /></dt>
</txp:if_different>
<txp:if_different>
  <dt class="month"><txp:posted format="%B" /></dt>
</txp:if_different>
  <dd><a href="<txp:permlink />"><txp:title /></a>
  <txp:posted format="%h. %e" /></dd>

Step 2: Create an Archive Page

Page Name: Archive

<dl class="archive-list">
  <txp:article_custom form="archive.list" section="archive" />
</dl>

Be sure to replace section="archive" with the name of your default article section.

Step 3: Create an Archive Section

  1. Go to the Presentation tab and choose Sections from the sub tabs.
  2. Type in the name of the section you’d like and press Create. For this example we are using “Archive”.
  3. Scroll down to the Section name you just created and select the page that you created in the Uses Page: select box. For this example we are using “Archive”.
  4. Press Save.

Preview

Navigate to your newly created section to see how it all looks. With a little CSS and creativity you can make some interesting archive pages without any need for a plugin.

Check out my Archive page to see what I came up with.

Short URL: http://ersk.in/40

Comment (2)

# 1

Nathan Logan said on August 24, 2009 @ 10:18 AM...

Dig the tutorial, but not the biggest fan of the markup. In this scenario, wouldn’t a layout more like this be more semantic?

<ul>
  <li>year
    <ul>
      <li>month
        <ul>
          <li>post</li>
          <li>post</li>
        </ul>
      </li>
    </ul>
  </li>
</ul>

But overall, I really dig the look of your archive page – want to design mine? =)

P.S. I couldn’t apply <code> or <pre>, or spend any more time trying to get them to look right, hence the formatting mess. Just imagine them indented correctly.

EDIT: I fixed it for ya? - Craig

# 2

Craig said on August 24, 2009 @ 10:39 AM...

@Nathan Logan
Yeah... I tried that when I first built my archive page. Sadly, that list format is not possible without writing a plugin. I really wanted to write a tutorial that used only the native Textpattern tags and didn’t rely on any plugins.

Thanks for the comment.

Leave a comment...