Module

Developer
Supported

Sitemap Module

ExpressionEngine 3, ExpressionEngine 4, ExpressionEngine 5

Back to this add-on's main page
View Other Add-ons From PutYourLightsOn

     

You must be logged in to post.

Handling Categories in Site Map URLs

Support (Resolved)

rdingus
rdingus

Hi,

We have complex nested Categories defined for our Channels.  URLs on our EE site are then generated in templates with the following code inside of a channel:entries tag:

{categories limit=‘1’ group_id=‘1’ parent_only=‘yes’}
  {if count > 0}
  <a href=”/expertise/{category_url_title}/insights/{url_title}”>
  {if:else}
  <a href=”#”>
  {/if}
{/categories}

When I activate these channels in the site map it pulls the incorrect {category_url_title} for the URL.  Is there a way to handle this within the site map plugin?

PutYourLightsOn
# 1
Developer
PutYourLightsOn

how are you entering the url for these channels in the sitemap module? the {cat_url_title} tag is supported as explained in the module preferences section of the docs.

rdingus
# 2
rdingus

Thanks for you’re help.

I’m entering the URLs like this, per the docs:  http://domain.com/expertise/{cat_url_title}/insights/{url_title}

However, this generates incorrect URLs because it inputs the wrong {cat_url_title} value. 

The plugin creates this URL:  http://domain.com/expertise/payment-delivery-reform/insights/new-trends-and-analysis-for-aco-participants

But the correct URL should be:  http://domain.com/expertise/managed-care/insights/new-trends-and-analysis-for-aco-participants

If you look at the code sample above when we generate these URLs on the site we limit the categories to group_id=‘1’ and parent_only=‘yes’. 

Is there a way to handle this?

PutYourLightsOn
# 3
Developer
PutYourLightsOn

are your entries assigned to more than one category? as per the docs:

if an entry is assigned to multiple categories then only the first category will be used in parsing

rdingus
# 4
rdingus

Ok, in some cases we have parent categories with IDs that are greater than child category IDs.  In this case it is pulling the Child category as “first”.  But I need to pull the parent category.  Where in the plugin code can I change this?  We cannot easily change the category IDs.

rdingus
# 5
rdingus

FYI, I was able to get this working by modifying the query in mod.sitemap.php starting on line 132.

PutYourLightsOn
# 6
Developer
PutYourLightsOn

good to hear, would you mind posting your changed code here for anyone trying to do something similar in future?

Bhashkar Yadav
# 7
Bhashkar Yadav

I am having the issue something like this. The site is having URL like siteurl.com/product/{parent_category}/{child_category}/{url_title}

Could you please let me know if there is any way to handle it.

Thanks,

PutYourLightsOn
# 8
Developer
PutYourLightsOn

Sorry Bhashkar, Sitemap only supports using a single category in the URL template.

Bhashkar Yadav
# 9
Bhashkar Yadav

Thanks for your quick response.

Could you please help me with any hack if possible.

Thanks,

PutYourLightsOn
# 10
Developer
PutYourLightsOn

It’s actually a fairly involved change to the query (the current query uses a JOIN statement to grab the single category, whereas fetching multiple categories would require a separate query altogether) - so it’s beyond a quick hack I can offer here. To tackle it yourself, start around line 214 of mod.sitemap.php.

Bhashkar Yadav
# 11
Bhashkar Yadav

Thanks for your quick response.

Yes, I did it successfully. I added a new tag {cat_breadcrumbs} and made URL like:

siteurl.com/product/{cat_breadcrumbs}/{url_title} 

But found another limitation. Only one URL can be added per channel. I think, there would be facility to add more than one URL per channel.

Not sure how to resolve it at my end :( .


Thanks

PutYourLightsOn
# 12
Developer
PutYourLightsOn

Clever workaround Bhashkar.

Re: “one URL per-channel” - those are simply URL templates. Sitemap will in actuality output a sitemap node which follows that template for each entry in each channel you assign it to.