Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

Low-Overhead Archives By Month (See related posts)

You used to have to use rss_suparchive to get an archive of articles broken out by month, but this plugin produces an ungodly number of db queries when dealing with large archives (e.g., hundreds or thousands of articles).

Textpattern 4.0.2 allows you to get the same effect using the good ol' <txp:article> tag, which uses a LOT FEWER database queries.

You can see this in action at Not Far North.

First, you need the glx_if plugin installed.

put this in your "article" page template:

<txp:glx_if_section_frontpage>
   <h2>Archives</h2>
   <dl class="archivelist">
     <txp:article section="article" form="article_archive" />
   </dl>
</txp:glx_if_section_frontpage>

<txp:if_individual_article>
   <txp:article />
</txp:if_individual_article>


If you were attentive, you see that we also need an article_archive form. Create that form and put this in it:

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

<dd><txp:permlink><txp:title /></txp:permlink>
<br /><txp:excerpt /></dd>


Now, "yoursite.com/article" will display a list of articles broken out by month, and "yoursite.com/article/2/helloworld" will display only that article using the "default" form.

To handle category listings, install the upm_category_title plugin and add this to your front page ("default") template:

<txp:glx_if_category_list>
   <h2>Articles in <txp:upm_category_title /></h2>
   <p><a href="/article/">View all articles</a></p>

   <dl class="archivelist">
     <txp:article section="article" form="article_archive" />
   </dl>
</txp:glx_if_category_list>

<txp:glx_if_not_category_list>
   <txp:article limit="2" form="article_newest" />
</txp:glx_if_not_category_list>


Note that using the above bit of code requires you to modify the glx_if plugin a bit - more about that in another snippet (it's really easy).

Comments on this post

mary posts on Nov 18, 2005 at 04:07
You can also do the first and third with built-in tags (indented/spaced for clarity):

<txp:if_article_list>

        <h2>Archives</h2>

        <dl class="archivelist">
                <txp:article form="article_archive" />
        </dl>

<txp:else />

        <txp:article />

</txp:if_article_list>


<txp:if_article_list>
<txp:if_category>

   <h2>Articles in <txp:upm_category_title /></h2>
   <p><a href="/article/">View all articles</a></p>

   <dl class="archivelist">
     <txp:article form="article_archive" />
   </dl>

<txp:else />

        <txp:article limit="2" form="article_newest" />

</txp:if_category>
</txp:if_article_list>


You can even combine them,

one way

<txp:if_article_list>

        <txp:if_category>

                <h2>Articles in <txp:upm_category_title /></h2>
                <p><a href="/article/">View all articles</a></p>

                <dl class="archivelist">
                        <txp:article form="article_archive" />
                </dl>

        <txp:else />

                <h2>Archives</h2>

                <dl class="archivelist">
                        <txp:article form="article_archive" />
                </dl>

        </txp:if_category>

<txp:else />

        <txp:article />

</txp:if_article_list>



or another

<txp:if_article_list>

        <txp:if_category>

                <h2>Articles in <txp:upm_category_title /></h2>
                <p><a href="/article/">View all articles</a></p>

                <dl class="archivelist">
                        <txp:article form="article_archive" />
                </dl>

        <txp:else />

                <txp:article limit="2" form="article_newest" />

        </txp:if_category>

<txp:else />

        <txp:article />

</txp:if_article_list>
joeldueck posts on Nov 23, 2005 at 16:46
Thanks mary, guess I'm still stuck in gamma world in a lot of ways. I've changed the pages at notfarnorth.com to use this method and it works great!

You need to create an account or log in to post comments to this site.


Related Posts