Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2020-09-27 01:46:05

Myusername
Member
Registered: 2019-12-12
Posts: 73

Automatically create sitemaps when needed?

I created a sitemap using a form like this

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
	<txp:article_custom limit='999'>
		<url>
			<loc><txp:permlink/></loc>
			<lastmod><txp:modified format="iso8601" /></lastmod>
		</url>
	</txp:article_custom>
</urlset>

When I did it, I didn’t even think about what would be done when I reached the limit of 999 articles. For now I only increased the limit, since according to google itself the limit is much greater than 999 articles.

However, it is recommended to split large sitemaps into other smaller sitemaps. In the worst case scenario I will have to create it manually, but I really didn’t want to do it.

The solution I thought was the following: when you reach the limit of 999 articles, create another form in the database with the same content, but with an offset of 999, and so on successively as you reach the limit. But I don’t know where to start to reach that goal. Any tips? Maybe somehow easier?

Offline

#2 2020-09-27 06:48:03

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 8,296
Website

Re: Automatically create sitemaps when needed?

Hi, Your sitemap should be

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
	<txp:article_custom limit="999">
		<url>
			<loc><txp:permlink/></loc>
			<lastmod><txp:modified format="iso8601" /></lastmod>
		</url>
	</txp:article_custom>
</urlset>

sitemap 2

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
	<txp:article_custom offset="999" limit="999">
		<url>
			<loc><txp:permlink/></loc>
			<lastmod><txp:modified format="iso8601" /></lastmod>
		</url>
	</txp:article_custom>
</urlset>

Just as a note, at the moment I have over 1900 articles in our sitemap using a 9999 limit, and experience no issues.


Yiannis
——————————
neme.org | hblack.net | LABS | State Machines | NeMe @ github | Covid-19; a resource
I do my best editing after I click on the submit button.

Offline

#3 2020-09-27 10:02:56

etc
Developer
Registered: 2010-11-11
Posts: 3,940
Website

Re: Automatically create sitemaps when needed?

Why would you need another form? If you replace <txp:article_custom /> with <txp:article />, it will observe URL pg parameter and set the offset accordingly. To generate an automatic list of sitemap links <txp:pages /> tag should help.

A good shortcode candidate ;-)

Offline

#4 2020-09-27 13:08:13

Myusername
Member
Registered: 2019-12-12
Posts: 73

Re: Automatically create sitemaps when needed?

etc wrote #326123:

Why would you need another form? If you replace <txp:article_custom /> with <txp:article />, it will observe URL pg parameter and set the offset accordingly. To generate an automatic list of sitemap links <txp:pages /> tag should help.

A good shortcode candidate ;-)

I hadn’t thought of that. Great.

Offline

#5 2020-09-28 13:34:59

philwareham
Core designer
From: Haslemere, Surrey, UK
Registered: 2009-06-11
Posts: 3,396
Website

Re: Automatically create sitemaps when needed?

etc wrote #326123:

To generate an automatic list of sitemap links <txp:pages /> tag should help.

Hi Oleg – can you provide an example of this? I current use <txp:article /> tag in sitemaps but if there is a more performant way I’d be keen to know (I could then also document it in the Textpattern user docs, <txp:pages /> tag page).

Offline

#6 2020-09-28 17:18:04

etc
Developer
Registered: 2010-11-11
Posts: 3,940
Website

Re: Automatically create sitemaps when needed?

philwareham wrote #326153:

I current use <txp:article /> tag in sitemaps but if there is a more performant way I’d be keen to know (I could then also document it in the Textpattern user docs, <txp:pages /> tag page).

Hi Phil, nothing special, sorry. I just thought of generating a sitemap index like this in a custom XML-type form:

<?xml version="1.0" encoding="UTF-8"?>
<txp:pages total='<txp:article_custom pageby="10000" pgonly />' />
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
   <txp:pages total shift link="" break="sitemap">
      <loc><txp:site_url />?f=sitemap&pg=<txp:yield item="page" /></loc>
   </txp:pages>
</sitemapindex>

Then in sitemap form one can output articles with offset via <txp:article />, as you do.

Offline

#7 2020-09-28 17:39:57

etc
Developer
Registered: 2010-11-11
Posts: 3,940
Website

Re: Automatically create sitemaps when needed?

But, according to this, one can have up to 50000 URLs per sitemap, so we don’t really need to develop on this.

Offline

Board footer

Powered by FluxBB