Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2025-09-29 03:20:21

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,294
Website GitHub Mastodon Twitter

List of all article list page urls

How can I get a list of all article list page urls for a particular section starting from page 2? I’m needing this for the sitemap.

I’m looking for something like:

<txp:variable name="siteurl" />section_name/?pg=2
<txp:variable name="siteurl" />section_name/?pg=3
<txp:variable name="siteurl" />section_name/?pg=4
...
<txp:variable name="siteurl" />section_name/?pg=x

Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#2 2025-09-29 03:54:12

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,294
Website GitHub Mastodon Twitter

Re: List of all article list page urls

OK, I got this with php, but I was wondering if it could be done with tags οr without having to specify the $endPage.

<txp:php>
$siteUrl = 'https://www.site.tld';
$section = 'section_name';
$startPage = 2;
$endPage = 100;

for ($i = $startPage; $i <= $endPage; $i++) {
echo "<url>";
echo "<loc>{$siteUrl}/{$section}/?pg={$i}</loc>";
echo "<changefreq>monthly</changefreq>";
echo "</url>";
}
</txp:php>

Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#3 2025-09-29 08:31:03

etc
Developer
Registered: 2010-11-11
Posts: 5,502
Website GitHub

Re: List of all article list page urls

You can calculate and plug endPage into <txp:php />:

<txp:php endPage='<txp:article_custom section="section_name" pageby="10" pgonly />'>
...
</txp:php>

There is also <txp:pages /> solution (instead of <txp:php />), but I don’t remember howto.

Offline

#4 2025-09-29 09:00:07

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,294
Website GitHub Mastodon Twitter

Re: List of all article list page urls

etc wrote #340753:

You can calculate and plug endPage into <txp:php />:

Thanks so much Oleg. It might take me a few days as, as you know my php skills are rudimentary.


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#5 2025-09-29 16:33:28

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,294
Website GitHub Mastodon Twitter

Re: List of all article list page urls

This is what I have tried:

<txp:variable name="latest_posted_article"><txp:article_custom section="my_section" limit="1" exclude="2240,2241" sort="posted desc" status="live"><txp:modified format="w3c" /></txp:article_custom></txp:variable>
<txp:variable name="page_count"><txp:evaluate query='<txp:article_custom section="my_section" pageby="10" pgonly /> - 1' /></txp:variable>
<txp:php>
$siteUrl = 'https://www.site.tld';
$section = 'my_section';
$startPage = 2;
$pagesNumber = "<txp:variable name='page_count' />";
$endPage = $pagesNumber;
$latestModified = '<txp:variable name="latest_posted_article" />';

for ($i = $startPage; $i <= $endPage; $i++) {
echo "<url>";
echo "<loc>{$siteUrl}/{$section}/?pg={$i}</loc>";
echo "<lastmod>{$latestModified}</lastmod>";
echo "</url>";
}
</txp:php>

but I’m getting an out of memory error because of the evaluate tag. The sitemap as it is currently generated can be found on github.


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#6 2025-09-29 19:02:53

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 5,031
Website GitHub

Re: List of all article list page urls

Oleg’s example shows you how to pass the results of a parsed tag to a txp:php block as a ready-to-use php variable, so you should be able to do:

<txp:php endPage='<txp:article_custom section="section_name" pageby="10" pgonly />' 
         latestModified='<txp:article_custom section="section_name" limit="1" exclude="2240,2241" sort="posted desc" status="live"><txp:modified format="w3c" /></txp:article_custom>'>
$siteUrl = 'https://www.site.tld';
$section = 'my_section';

for ($i = 1; $i <= ($endPage - 1); $i++) {
    echo "<url>";
    echo "<loc>{$siteUrl}/{$section}/?pg=" . ($i + 1) . "</loc>";
    echo "<lastmod>{$latestModified}</lastmod>";
    echo "</url>";
}
</txp:php>

So if endPage returns 10 pages, it will loop over $i = 1 to 9, but output pg=2 to 10.


TXP Builders – finely-crafted code, design and txp

Offline

#7 2025-09-29 19:12:34

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 5,031
Website GitHub

Re: List of all article list page urls

Wondering aloud, can you loop over a from-to range using a core tag? I know that’s possible with rah_repeat and maybe smd_each. If so, you wouldn’t need the php block at all.


TXP Builders – finely-crafted code, design and txp

Offline

#8 2025-09-29 19:43:56

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 5,031
Website GitHub

Re: List of all article list page urls

More thinking aloud. Would this alternative approach work, which uses txp:variable to loop over a comma-separated list?

<txp:variable name="lastmodified_article"><txp:article_custom section="section_name" limit="1" exclude="2240,2241" sort="posted desc" status="live"><txp:modified format="w3c" /></txp:article_custom></txp:variable>
<txp:php variable="page_nums" page_count='<txp:article_custom section="articles" pageby="5" pgonly />'>
    // make a string: 2,3,4,5,6,… and save in a variable
    $numbers = range(2, $page_count);
    echo implode(',', $numbers);
</txp:php>

<txp:variable name="page_nums" breakby output>
    <url>
        <loc><txp:site_url />section_name/?pg=<txp:yield item /></loc>
        <lastmod><txp:variable name="lastmodified_article" /></lastmod>
    </url>
</txp:variable>

I’m not sure that txp:variable containers can produce output like that?

EDIT: It seems not, however you can put the output into a separate form and then specify that as the breakform, e.g.

<txp:variable name="page_nums" breakby breakform="sitemap_item" output />

and the breakform sitemap_item (of type misc):

<url>
    <loc><txp:site_url />section_name/?pg=<txp:yield item /></loc>
    <lastmod><txp:variable name="lastmodified_article" /></lastmod>
</url>

TXP Builders – finely-crafted code, design and txp

Offline

#9 2025-09-29 21:07:13

etc
Developer
Registered: 2010-11-11
Posts: 5,502
Website GitHub

Re: List of all article list page urls

Amazing that breakform works (?) here, it turns <txp:variable /> into universal iterator. You can also use <txp:pages /> for numeric ranges:

<txp:pages total='<txp:article_custom section="articles" pageby="5" pgonly />' break="url" link="">
    <txp:yield item="page" /><!-- add extra markup here -->
</txp:pages>

Offline

#10 2025-09-30 05:08:17

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,294
Website GitHub Mastodon Twitter

Re: List of all article list page urls

jakob wrote #340768:


EDIT: It seems not, however you can put the output into a separate form and then specify that as the breakform, e.g.

<txp:variable name="page_nums" breakby breakform="sitemap_item" output />...

and the breakform sitemap_item (of type misc):

<url>...

My next test:)


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#11 2025-09-30 08:18:04

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 5,031
Website GitHub

Re: List of all article list page urls

etc wrote #340771:

You can also use <txp:pages /> for numeric ranges:

As ‘entertaining’ as my detour using txp:variable to loop over items was, Oleg’s solution is more elegant and succinct (as one would expect ;-):

<txp:variable name="lastmodified_article"><txp:article_custom section="section_name" limit="1" sort="posted desc" status="live"><txp:modified format="w3c" /></txp:article_custom></txp:variable>

<txp:pages total='<txp:article_custom section="section_name" pageby="10" pgonly />' break="url" link="" offset="1">
    <loc><txp:site_url />section_name/?pg=<txp:yield item="page" /></loc>
    <lastmod><txp:variable name="lastmodified_article" /></lastmod>
</txp:pages>

I just tried it out on the dev demo site (should be online for another 40 minutes after this post) and it works great! (add offset="1" to Oleg’s code to start with pg=2).


TXP Builders – finely-crafted code, design and txp

Offline

#12 2025-09-30 08:57:31

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,294
Website GitHub Mastodon Twitter

Re: List of all article list page urls

Thanks so much to both of you. That works as intended and there is no problem with memory usage either!!!


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

Board footer

Powered by FluxBB