Publisher does not support the Fluid field type. Please do not contact asking when support will be available.

If you purchased an add-on from expressionengine.com, be sure to visit boldminded.com/claim to add the license to your account here on boldminded.com.

Ticket: Creating a multi language sitemap

Status Resolved
Add-on / Version Publisher 2.10.3
Severity
EE Version 4.3.6

Lincoln Gbenga Olagbaju

Nov 29, 2018

Hi Brian,
I’d like to make a template that generates an XML sitemap for my multi-language site that contains all entries in all languages as indicated by Google.
I need to output the language variants for each URL.

Example of a sitemap for 2 languages

<url>
<loc>http://www.example.com/page.html</loc>
<xhtml:link rel="alternate" hreflang="it" href="http://www.example.com/it/page.html"/>
<xhtml:link rel="alternate" hreflang="en" href="http://www.example.com/page.html"/>
</url>

I tried to replicate using this code for my sitemap, but the

translated_url

  variable is not outputing the links to each entry.

{exp:channel:entries channel="channel" dynamic="no" disable="relationships|member_data|pagination"}
<url>
<loc>{root_url}temp/{url_title}</loc>
{exp:publisher:languages}
<xhtml:link 
rel="alternate" 
hreflang="{short_name}" 
href="{translated_url}" />
{/exp:publisher:languages}
<lastmod>{edit_date format="%Y-%m-%dT06:00:00+00:00"}</lastmod>
<changefreq>weekly</changefreq>
</url>
{/exp:channel:entries}

Can you please take a look.

#1

BoldMinded (Brian)

The {translated_url} variable does not work like that inside of an entries tag. You need to build the URL of each entry, or use {page_url} if using Pages or Structure, or {url_title_path=”template-group/template”}.

Try reversing your tags:

{exp:publisher:languages}
{exp:channel:entries channel="channel" dynamic="no" disable="relationships|member_data|pagination" publisher_lang_id="{language_id}"}
 ...
{/exp:channel:entries} 
{/exp:publisher:languages}
#2

Lincoln Gbenga Olagbaju

Comment has been marked private.

#3

BoldMinded (Brian)

You may need to get more creative with your template code. Use the variables available to you…

Instead of {url_title_path} try {site_url}{language_code}/{url_title}

#4

Lincoln Gbenga Olagbaju

Comment has been marked private.

#5

BoldMinded (Brian)

How come you want to put all the languages into a single sitemap file? Usually you make a sitemap file for each language, e.g. /it/sitemap, /fr/sitemap etc, and it only shows 1 language.

#6

Lincoln Gbenga Olagbaju

Comment has been marked private.

#7

BoldMinded (Brian)

There is an {exp:publisher:translate_url url=”whatever”} that may work.

TBH this isn’t a scenario that has come up before… trying to list out all entries with different translations on the same page. I asked about why you’re trying to do it all in 1 sitemap b/c the company I work for has an SEO company that actually recommended different urls, e.g. jamf.com/sitemap, jamf.com/de/sitemap, jamf.com/fr/sitemap.

#8

Lincoln Gbenga Olagbaju

Brian, i’ve already tried

{exp:publisher:translate_url url=“whatever”}

no results. Can you please show an example of how to achieve different sitemaps for each language?

#9

BoldMinded (Brian)

You make it just like any other sitemap template file, and the language prefix determines which entries to show and the url translations.

#10

Lincoln Gbenga Olagbaju

Comment has been marked private.

#11

Lincoln Gbenga Olagbaju

Comment has been marked private.

#12

BoldMinded (Brian)

Lincoln, I’m not sure I can just show you code to make an Italian version because that is a pretty generalized request. This isn’t something that is normally handled with add-on support. I don’t know what your use case is or what other specifics you may have going on with your site. Adding publisher_lang_id to the entries tag lets you change which language that entries tag is listing, thus ignoring any site cookies or language codes in the url, but making the URLs translate in that case may be a different story.

I’ll add a lang_id parameter to the translated_url template tag, which may help you. I’ll send you a new build in the next day or two.

#13

Lincoln Gbenga Olagbaju

Hi, i don’t think mine is a generalized request, since there is no example or tag to use in the docs to achieve a list of translated urls of the second language to use on a sitemap. There are no issues with my site, and not sure why what i’m asking for has never come up.

Thanks the same in taking time to add the lang_id parameter.

#14

BoldMinded (Brian)

I can’t add examples for every possibility to the docs 😊 Trust me, its amazing what has taken years to come up. I just haven’t seen a request to show urls to entries in a language other than the currently active language.

#15

BoldMinded (Brian)

Comment has been marked private.

#16

Lincoln Gbenga Olagbaju

Sure, that’s not possible. But creating a sitemap is a normal standard, there is need to fetch entries urls for a specific language SEO wise.

#17

BoldMinded (Brian)

Try the build in the previous comment. The to_lang_id and from_lang_id parameters were added.

{exp:publisher:translate_url from_lang_id="1" to_lang_id="2" url="foobar"}

Hopefully that helps.

#18

Lincoln Gbenga Olagbaju

Comment has been marked private.

#19

BoldMinded (Brian)

Did you try out the new parameters on the translate_url tag?

#20

BoldMinded (Brian)

Oh, duh, I just saw that in your code. Glad it worked out!

Login to reply