Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#1 2024-12-31 02:28:28
- hug
- Member
- Registered: 2024-12-02
- Posts: 11
Article list months inside years (level break inside a level break)
I’m attempting to create an archive article list that looks something like this:
<h2>2024</h2>
<h3>December</h3>
Article link
Article link
<h3>September</h3>
Article link
<h2>2023</h2>
<h3>November</h3>
Article link
Article link
I was able to get halfway there with the “spaceship” <+>
(which I can’t search in the forums, hahaha). Here is my archive page portion:
<txp:article_custom sort="Posted desc, Title desc" section="Articles" limit="0" breakby="<txp:posted format='%Y' />" breakform="minimum_archive_lb_year">
<p>
<txp:posted format="%Y" />
·
<txp:posted format="%B" />
·
<txp:title />
·
Excerpt: “<txp:excerpt wraptag="" wrapform="" escape="p, tidy, textile" />”
</p>
</txp:article_custom>
And the minimum_archive_lb_year form:
<h2><txp:posted format="%Y" /></h2>
<+>
That got me here:
<h2>2024</h2>
2024 · December · Random TextPattern tips · Excerpt: “”
2024 · December · The Oracle of Delphi, Priestess Pythia, Who Spoke Truth to Power by Julia Kindt · Excerpt: “”
2024 · December · The Traveller by Arlene Bailey · Excerpt: “”
2024 · November · Reading glasses splurge · Excerpt: “”
2024 · November · Minimum Textpattern theme · Excerpt: “”
2024 · October · Helm shutting down · Excerpt: “The Helm server, touted as an on-premise home email and file server, shut down in 2022.”
<h2>2022</h2>
2022 · December · A-series paper sizes · Excerpt: “”
2022 · November · Apple MacOS upgrading to Monterey · Excerpt: “Notes on third-party ssds when upgrading to Apple MacOS Monterey.”
...
Then to do the same to get monthly headings, I thought I could add another article_custom
inside and restrict it to the year currently being processed and have it output the months’ posts in that year.
<txp:article_custom sort="Posted desc, Title desc" section="Articles" limit="0" breakby="<txp:posted format='%Y' />" breakform="minimum_archive_lb_year">
<txp:article_custom sort="Posted desc, Title desc" section="Articles" limit="0" breakby="txp:posted format='%B' />" breakform="minimum_archive_lb_month" month="<txp:posted format='%Y' />">
<p>
<txp:posted format="%Y" />
·
<txp:posted format="%B" />
·
<txp:title />
·
Excerpt: “<txp:excerpt wraptag="" wrapform="" escape="p, tidy, textile" />”
</p>
</txp:article_custom>
</txp:article_custom>
And here’s the minimum_archive_lb_month.
<h3><txp:posted format="%B" /></h3>
<+>
However, while that did the level break for the years, it dropped the content.
<h2>2024</h2>
<h2>2022</h2>
<h2>2021</h2>
...
I even tried a variation where I put the nested article_custom
inside the minimum_archive_lb_year form, but with the same result of only the year headings with no article list. Somewhere in the process the spaceship <+>
information is being eaten.
I feel like I’m missing something that’s hopefully realtively simple?
Offline
Re: Article list months inside years (level break inside a level break)
You should look at the if_different tag. That only outputs its contained content if it differs from last time it was seen.
We should probably add a specific example to the docs for a date-based archive as it’s a fairly common situation. There are a couple of txptips that use if_different, which you may be able to tweak for your situation
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
#3 2024-12-31 14:16:37
- hug
- Member
- Registered: 2024-12-02
- Posts: 11
Re: Article list months inside years (level break inside a level break)
Thanks again, Bloke, for the great suggestions! That was much easier to implement, and it worked perfectly.
Here’s the revised part of the archive
page. No longer using breakby, breakform, or the forms. (As for the Title desc
in the sorting, I have a collection of my mother’s poetry on site, and some of it was not dated so I assigned them the same date: 1 Jan 1970. This way if we were moving forward in time, those poems would be read alphabetically by title instead of id
order or something unpredictable.)
<txp:article_custom sort="Posted desc, Title desc" section="Articles" limit="0">
<txp:if_different>
<h2><txp:posted format="%Y" /></h2>
</txp:if_different>
<txp:if_different>
<h3><txp:posted format="%B" /></h3>
</txp:if_different>
<p>
<strong><txp:title /></strong><br/>
Excerpt: “<txp:excerpt escape="p, tidy, textile" />”
</p>
</txp:article_custom>
The if_different
tags should be placed in order that the desired output occurs. The first “level” is the h2
heading for the year and the next level is the h3
heading for the month. Under each month are the listed articles, just as desired above. The output for the <p>
tag is the normal condition.
<h2>2024</h2>
<h3>December</h3>
Article link
Article link
<h3>September</h3>
Article link
<h2>2023</h2>
<h3>November</h3>
Article link
Article link
Here’s the output from my site. (I still need to style the articles and link them, add excerpts.)
<h2>2024</h2>
<h3>December</h3>
<strong>Random TextPattern tips</strong>
Excerpt: “”
<strong>The Oracle of Delphi, Priestess Pythia, Who Spoke Truth to Power by Julia Kindt</strong>
Excerpt: “”
<strong>The Traveller by Arlene Bailey</strong>
Excerpt: “”
<h3>November</h3>
<strong>Reading glasses splurge</strong>
Excerpt: “”
<strong>Minimum Textpattern theme</strong>
Excerpt: “”
<h3>October</h3>
<strong>Helm shutting down</strong>
Excerpt: “The Helm server, touted as an on-premise home email and file server, shut down in 2022.”
<h2>2022</h2>
<h3>December</h3>
<strong>A-series paper sizes</strong>
Excerpt: “”
<h3>November</h3>
<strong>Apple MacOS upgrading to Monterey</strong>
Excerpt: “Notes on third-party ssds when upgrading to Apple MacOS Monterey.”
I’m still in the process of moving content from older versions of the site with content from Hugo, Grav, Octopress, and wherever else I have stashed from backups.
I like the minimum theme a lot with its focus on reading, but it’s a little too minimal, haha. I’m trying to do a “minimum plus” for lack of a better word.
Offline
Re: Article list months inside years (level break inside a level break)
hug wrote #338647:
However, while that did the level break for the years, it dropped the content.
The problem might come from month="<txp:posted format='%Y' />"
, because attribute values inside double quotes are not parsed. But using <txp:if_different />
is more pertinent in this case.
Offline
#5 2024-12-31 20:15:23
- hug
- Member
- Registered: 2024-12-02
- Posts: 11
Re: Article list months inside years (level break inside a level break)
Thanks for the insight, etc! Yes, since everything is working, I’m leaving it alone.
I did find one edge case with if_different
: It just so happens that the oldest post in 1975 was in January, and the posts in 1970 are also January. Since the last if_different
for the month was January, it didn’t output one even though the year changed. I understand this is because each if_different
section is independent. I think this may be resolved as I add more content to the site, but it would be nice to have a mechanism that says, “when the H2 changes, always output an H3.”
<h2>1975</h2>
<h3>January</h3>
<strong>They</strong>: A poem by Bonnie Goodbar. They say inflation is getting worse. (Two versions.)
<h2>1970</h2>
<!-- January should be here, logically because the year changed, the month should also output. -->
<strong>Come the daybreak, come the dawn (unfinished)</strong>: A poem by Bonnie Goodbar. Come the daybreak, come the dawn.
<strong>Blossoms, Blossoms Everywhere (unfinished)</strong>: A poem by Bonnie Goodbar. Blossoms, blossoms everywhere.
Offline
Re: Article list months inside years (level break inside a level break)
hug wrote #338652:
it would be nice to have a mechanism that says, “when the H2 changes, always output an H3.”
This mechanism is called test
:
<txp:if_different test='<txp:posted format="%Y-%m" />'>
<h3><txp:posted format="%B" /></h3>
</txp:if_different>
Happy New Year everyone!
Offline
#7 2025-01-02 04:11:07
- hug
- Member
- Registered: 2024-12-02
- Posts: 11
Re: Article list months inside years (level break inside a level break)
etc wrote #338653:
This mechanism is called
test
:
<txp:if_different test='<txp:posted format="%Y-%m" />'>...
Happy New Year everyone!
Absolutely perfect! Y’all are the best! Happy New Year!!
Offline