Custom Category URLs

Kevin Kim-Murphy asked on July 1, 2015 18:49

Hi. Been searching on the forum for this - and unable to find the answer I am looking for.

I have pages on our site that are for specific categories - and when I use the Category List webpart to link to those pages we get a URL like: domain.com/pagename?categoryid=22

I can see that we have the option in the Category List webpart to use the Category ID or the Category Codename - but even then it still has that code association in the URL: domain.com/pagename?categoryname=LargeItems

I would like to have the URL be something like this:

domain.com/pagename/categorycodename

OR even better

domain.com/categorycodename

I can't seem to find a way to do this dynamically - please advise.

Thank you! Kevin

Correct Answer

Kevin Kim-Murphy answered on July 14, 2015 21:26

Roman, I was finally able to come up with a solution for this issue:

a) Configuring Kentico to create a category list with the following format for cateogry URLs: /pagename/categoryname vs. /pagename?categoryname=categoryname

b) Configuring the page to have an alias to resolve that pagename/categoryname alias.

The first issue (a) required that I clone the Category List webpart - naming the new web part "CategoryListCustomURL" - and then modify the line in the CategoryListCustomURL.ascx.cs file :

url = URLHelper.AddParameterToUrl(url, "categoryname", category.CategoryName);

to this:

url = "/PAGENAME/" + category.CategoryName;

Then configure the new Category List Custom URL web part to "Use code name in URL".

The result is that the new list is created with the category link in this format: /pagename/categoryname

For the second issue (b) - I found that putting the /pagename/{categoryname} in the path or pattern field of the page's Properties > URL tab didn't work as smoothly as I would have liked.

The issue I ran into was that from the Category List the page rendered correctly - but THEN the page URL in the main menu was modified to retain that format - /pagename/categoryname - basically making it impossible to get back to just the /pagename page.

I found that the only way to avoid this was to then remove the /pagename/{categoryname} from the path or pattern field and save the page again.

This resulted in Kentico automatically creating an Alias for /pagename/{categoryname} so the cloned Category List webpart could resolve the links correctly - AND the /pagename URL in the main menu was not impacted.

It was an interesting excercise - and seems almost like there is a bug or conflict in Kentico that causes this behavior. Regardless - I was able to resolve it and now the Category List links work as required.

0 votesVote for this answer Unmark Correct answer

Recent Answers


Roman Hutnyk answered on July 4, 2015 03:08 (last edited on July 4, 2015 03:27)

Kevin,

There is really simple solution: navigate to your page in Pages application of Kentico Administration (CMS Desk -> Content for versions prior to 8), go to properties -> url area and enter following value to the path or pattern field:

/pagename/{categoryname} Or /{categoryname}

System will resolve categoryname as query string parameter. For more details check documentation @ https://docs.kentico.com/display/K81/Wildcard+URLs

Hope this helps.

0 votesVote for this answer Mark as a Correct answer

Kevin Kim-Murphy answered on July 7, 2015 22:23

Thank You Roman. This works partly - it solves the issue of being able to navigate to a page using the following URL structure:

domain.com/pagename/categorycodename

But I do not see how to update the Category List Web Part to dynamically create the URL that follows that structure.

In the "Navigation" section of the Web Part Properties - I have the following fields:

Page Path
Pages frame target
Use code name in URL (checkbox)

I have played around with options there - i.e. putting /pagename/{categoryname} in the Page Path, but that didn't work...

Still looking for the correct configuration so that the Categories List Web Part can dynamically send users to that URL from a list of Categories.

Thank you for your help on this.

Kevin

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.