Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2005-11-01 22:05:12

zem
Developer Emeritus
From: Melbourne, Australia
Registered: 2004-04-08
Posts: 2,579

Archive lists by month (section, category, etc) with 4.0.2

This new FAQ entry describes some techniques for creating a list of articles grouped by month, section, category etc, using the new <txp:if_different> tag:

How do I make an archive page?

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

<!-- show the year -->
<txp:if_different>
<h2><txp:posted format="%Y" /></h2>
</txp:if_different>
<!-- show the month -->
<txp:if_different>
<h3><txp:posted format="%B" /></h3>
</txp:if_different>
<!-- 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 (http://example.com/archive/ or http://example.com/?s=archive) will be used to display the list of articles. Select archive_list as the page template (“Uses page:”).

(more in the FAQ article)


Alex

Offline

#2 2005-11-01 22:09:36

thebombsite
Archived Plugin Author
From: Exmouth, England
Registered: 2004-08-24
Posts: 3,251
Website

Re: Archive lists by month (section, category, etc) with 4.0.2

Nice one zem! That should keep a few quiet for a week or two. :)


Stuart

In a Time of Universal Deceit
Telling the Truth is Revolutionary.

Offline

#3 2005-11-01 22:43:09

zem
Developer Emeritus
From: Melbourne, Australia
Registered: 2004-04-08
Posts: 2,579

Re: Archive lists by month (section, category, etc) with 4.0.2

btw, this isn’t as flexible as some of the archive plugins like rss_suparchive, but article_custom is much more efficient. rss_suparchive loads all articles into memory at once, which can cause memory limit problems.


Alex

Offline

#4 2005-11-02 22:28:43

michaelkpate
Moderator
From: Avon Park, FL
Registered: 2004-02-24
Posts: 1,379
Website GitHub Mastodon

Re: Archive lists by month (section, category, etc) with 4.0.2

Taking things a step further, I decided to see how close I could come to emulating the functionality of rss_suparchive with this method.

I changed the code in monthly_article to:

<code><txp:if_different>
<dt><a id=”<txp:posted format=“a%m%y” />”></a><txp:posted format=”%B %Y” /></dt>
</txp:if_different>
<dd><a href=”<txp:permlink />” title=“Permanent link to <txp:title />”><txp:title /></a></dd></code>

I call it with this code on the Archives page.

<code><h2>Archives</h2>
<dl>
<txp:article_custom limit=“99999” form=“monthly_article” />
</dl></code>

In order to emulate the functionality of rss_suparchive_menu, I placed this code in an article template called monthly_menu:

<code><li><a href=”<txp:siteurl />archives/<txp:posted format=”#a%m%y” />”><txp:posted format=”%B %Y” /></a></li></code>

And on the front page used this in the sidebar section:

<code><li>
<h2>Archives</h2>
<ul>
<txp:article_custom limit=“99999” form=“monthly_menu” />
</ul>
</li></code>

I still it will be preferable to have monthly archive pages again someday, but until then, this will do nicely. It is certainly better than the 404 errors I have been getting of late.

Last edited by michaelkpate (2005-11-03 02:46:00)

Offline

#5 2005-11-05 20:53:01

aesop1
Archived Plugin Author
Registered: 2004-09-19
Posts: 142

Re: Archive lists by month (section, category, etc) with 4.0.2

This is great, Alex, thanks.

In most instances, though, I still prefer the simplicity of using the month variable so that <code><txp:article /></code> can respond dynamically to the URL. This way, extra templates (via forms or page templates) aren’t required.

This does have its applications though — especially in mixed date archives, as you have demonstrated. But for my usage I rarely present information in this manner since the archive list can become overwhelming. I would rather swap out one list with another.

Offline

#6 2005-11-06 18:30:54

alexandra
Member
From: Cologne, Germany
Registered: 2004-04-02
Posts: 1,370

Re: Archive lists by month (section, category, etc) with 4.0.2

Great Micheal. Thank you very much. I used your example for a german article on Building an archive with TXP tags.

Offline

#7 2005-11-07 07:39:58

nfo
New Member
From: Vancouver
Registered: 2005-07-29
Posts: 7
Website

Re: Archive lists by month (section, category, etc) with 4.0.2

> zem wrote:

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

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

You should close the txp:permlink so it makes the archive page into actual links instead of text.

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

Sorry if you mentioned this somewhere already.

This was very usefull to me, considering I had an archive link on my page that was dead.
Thanks.

Offline

#8 2005-11-07 09:59:07

squaredeye
Member
From: Greenville, SC
Registered: 2005-07-31
Posts: 1,495
Website

Re: Archive lists by month (section, category, etc) with 4.0.2

nfo,
You made a boo boo. The title tag isn’t a paired tag. Its single.

To make your title’s into links it should look like this:
<code>
<txp:permlink><txp:title /></txp:permlink>
</code>

or

<code>
<a href=”<txp:permlink />” title=”<txp:title/>” ><txp:title /></a>
</code>

if you were going to use the single tag version of <code><txp:permlink></code>

If that helps. :)

Matthew


Offline

#9 2005-11-07 22:47:25

nfo
New Member
From: Vancouver
Registered: 2005-07-29
Posts: 7
Website

Re: Archive lists by month (section, category, etc) with 4.0.2

> ma_smith wrote:

> nfo,
>You made a boo boo. The title tag isn’t a paired tag. Its single.

>To make your title’s into links it should look like this:
><code>
><txp:permlink><txp:title /></txp:permlink>
></code>

I was just cutting/pasting zem’s example.
It looks the same whether you have the title a single or paired tag.

I just wanted to show that you need to close the permlink tag.

Offline

#10 2005-11-07 22:51:58

squaredeye
Member
From: Greenville, SC
Registered: 2005-07-31
Posts: 1,495
Website

Re: Archive lists by month (section, category, etc) with 4.0.2

Fair play, I guess Alex made the boo boo, unless it was on purpose and something really smart which we should all note? :)

matthew


Offline

#11 2005-11-23 14:32:47

peter
New Member
Registered: 2004-09-10
Posts: 5

Re: Archive lists by month (section, category, etc) with 4.0.2

Is there a way to display multiple (but not all) sections? I see that I can specify one section (section=“section1”) but when I tried section=“section1, section2” that doesn’t work.

Thanks for any help…

Offline

Board footer

Powered by FluxBB