Skip to main content
Add some alternate code to clarify answer.
Source Link
Alex Roper
  • 2.6k
  • 1
  • 12
  • 23

You can actually use a bit of Twig logic to determine your category URI formats.

Try this for your Category URI Format:

{parent ? parent.uri : 'what-we-do'}/{slug}

Which is just a more compact way of doing this:

{% if parent %}{{ parent.uri }}{% else %}what-we-do{% endif %}/{slug}

That will only add 'what-we-do' to the URI if the current category doesn't have a parent (top-level category). Otherwise, it prepends the entire parent's URI.

That should give you URIs like:

/what-we-do/service-one
/what-we-do/service-one/subservice-one-a
/what-we-do/service-one/subservice-one-b
/what-we-do/service-one/subservice-one-b/subservice-one-b-nested

You can actually use a bit of logic to determine your category URI formats.

Try this for your Category URI Format:

{parent ? parent.uri : 'what-we-do'}/{slug}

That will only add 'what-we-do' to the URI if the current category doesn't have a parent (top-level category). Otherwise, it prepends the entire parent's URI.

That should give you URIs like:

/what-we-do/service-one
/what-we-do/service-one/subservice-one-a
/what-we-do/service-one/subservice-one-b
/what-we-do/service-one/subservice-one-b/subservice-one-b-nested

You can actually use a bit of Twig logic to determine your category URI formats.

Try this for your Category URI Format:

{parent ? parent.uri : 'what-we-do'}/{slug}

Which is just a more compact way of doing this:

{% if parent %}{{ parent.uri }}{% else %}what-we-do{% endif %}/{slug}

That will only add 'what-we-do' to the URI if the current category doesn't have a parent (top-level category). Otherwise, it prepends the entire parent's URI.

That should give you URIs like:

/what-we-do/service-one
/what-we-do/service-one/subservice-one-a
/what-we-do/service-one/subservice-one-b
/what-we-do/service-one/subservice-one-b/subservice-one-b-nested
Source Link
Alex Roper
  • 2.6k
  • 1
  • 12
  • 23

You can actually use a bit of logic to determine your category URI formats.

Try this for your Category URI Format:

{parent ? parent.uri : 'what-we-do'}/{slug}

That will only add 'what-we-do' to the URI if the current category doesn't have a parent (top-level category). Otherwise, it prepends the entire parent's URI.

That should give you URIs like:

/what-we-do/service-one
/what-we-do/service-one/subservice-one-a
/what-we-do/service-one/subservice-one-b
/what-we-do/service-one/subservice-one-b/subservice-one-b-nested