Answers.Body: <p>If you go into your Category Group’s settings and set the following settings:</p>
  
  <ul>
  <li>Craft 2
  
  <ul>
  <li>Top Level URL Format: <code>{slug}</code></li>
  <li>Nested URL Format: <code>{parent.uri}/{slug}</code></li>
  </ul></li>
  <li>Craft 3
  
  <ul>
  <li>Category URI Format: <code>{parent.uri}/{slug}</code></li>
  </ul></li>
  </ul>
  
  <p>then you would be able to set your section’s Entry URL Format to this:</p>
  
  <ul>
  <li><p>Craft 2</p>
  
  <pre><code>{myCategoryField.last.uri}/{slug}
  </code></pre></li>
  <li><p>Craft 3</p>
  
  <pre><code>{myCategoryField.inReverse().one().uri}/{slug}
  </code></pre></li>
  </ul>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-10T09:33:32.290Z
Answers.Text: This is handy. Is there an easy way to just output just the child category and not include the parent?
Answers.UserDisplayName: shorn
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-10T13:14:58.320Z
Answers.Text: @shorn Not sure I’m following. Maybe post as its own question with more details?
Answers.UserDisplayName: Brandon Kelly
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-10T17:05:10.327Z
Answers.Text: Ok, will post up a question shortly.
Answers.UserDisplayName: shorn
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-06-18T16:11:57.127Z
Answers.Text: In regards to the Category URI Format, if you have a prefix before all category URI's, the example given here for Craft 3 results in the prefix being duplicated. In this case the following solution worked for me: `prefix/{parent.slug}/{slug}` (using `parent.slug` rather than `parent.uri`).
Answers.UserDisplayName: Mike
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-08-16T18:42:41.137Z
Answers.Text: @Mike - The problem with your solution prefix/{parent.slug}/{slug} is, that its only for 2 levels. The gandparent and the grand-grand-grandparent are not sluggified with this method. 
  Do u know what to do in this case?
Answers.UserDisplayName: Slowwie
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-08-17T05:05:41.803Z
Answers.Text: I dont really understand what this section´s Entry URL Format is. 
  After I changed the Category URI Format of the Category Group - I can get now 2 level URI's. Fine but what if my customer is nesting more levels. 
  What do u mean with section's Entry URL format?
  As I can see there is no section for Categories...
Answers.UserDisplayName: Slowwie
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-08-17T12:19:55.627Z
Answers.Text: @Slowwie This question is asking how to set _entries’_ URLs based on their selected categories. If you are just concerned with setting category URLs, you can safely ignore the part about sections (which contain entries). The category URL format above will work no matter how many levels you have.
Answers.UserDisplayName: Brandon Kelly
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-21T05:10:43.110Z
Answers.LastActivityDate: 2018-02-27T14:46:47.437Z
Answers.LastEditDate: 2018-02-27T14:46:47.437Z
Answers.UserDisplayName: Brandon Kelly
Body: <p>I'm trying to mimic the URL structure exactly how I have it in my old CMS. If I select an entry to have both a category and subcategory I would like to have the subcategory in the URL along with the category and the entry slug.</p>
  
  <p>For Example</p>
  
  <pre><code>http://example.com/cat1/subcat1/entry
  </code></pre>
  
  <p>Right now I have the Entry URL Format set to be <code>{category.first().slug}/{slug}</code>, but that only shows the first category. How do I access that optional <code>subcat1</code> subcategory in that field?</p>
  
  <p>EDIT</p>
  
  <p>I have tried the following but it doesn't work</p>
  
  <pre><code>{category.first.slug }/{ category.first.children.first.slug ? category.first.children.first.slug ~ '/' : '' }{slug}
  </code></pre>
  
  <p>I have also tried </p>
  
  <pre><code>{category[0].slug}/{ category[1] ? category[1].slug ~ '/': ''}{slug}
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-06-20T18:46:13.360Z
Comments.Text: Can you try and use double curly braces {{ .. }} , if I remember correctly there was a change in Craft 2.0 which makes them necessary.
Comments.UserDisplayName: Victor
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-06-20T18:48:18.783Z
Comments.Text: Just tried that, no difference unfortunately.
Comments.UserDisplayName: Seán O'Grady
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-06-20T20:01:07.677Z
Comments.Text: It seems that you want both of the following to load the entry template:
  
  http://example.com/cat1/subcat1/entry & 
  http://example.com/cat1/entry
  
  Is this correct?
  
  Probably you will need to use custom routes, and a bit of template logic to determine if a request segment is a category url or an entry url.  
  
  I've not run into a need for segment 1 as a category url, it has always been something like /catalog/cat/entry or news/cat/entry/  Is there a specific reason you are not doing this way?
Comments.UserDisplayName: Steve Adams
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-06-20T20:03:59.997Z
Comments.Text: Because the CMS I used before – Wordpress – structures posts with subcategories in the URL in this way. To be honest it makes the most sense, otherwise what is the point of subcategories in the first place?
Comments.UserDisplayName: Seán O'Grady
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-06-20T20:11:43.977Z
Comments.Text: So .com/cat1/ would list all entries in cat1 including its subs, and .com/cat1/sub1/ would list only sub1 entries? Then you have .com/cat1/entryA/ and .com/cat1/sub1/entryA/ ?  Craft is so flexible, you can make it behave however you need.  It will help if you update your question with more example urls and what you expect to happen with each one. :)
Comments.UserDisplayName: Steve Adams
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-06-20T21:03:23.213Z
Comments.Text: It is a bit strange I agree, but the category urls I have set to `example.com/category/<category-name>/` The category slugs in the entry URL are just for contextual tips for the user & for SEO purposes... Anyways the question is how, not why :)
Comments.UserDisplayName: Seán O'Grady
Tags: <categories><url><entry-type>
Title: How do I add a subcategory to the URL slug for a channel entry?
ThreadText: # How do I add a subcategory to the URL slug for a channel entry?
  
  (Asked by: username_0 on 2014-06-20)
  
  I'm trying to mimic the URL structure exactly how I have it in my old CMS. If I select an entry to have both a category and subcategory I would like to have the subcategory in the URL along with the category and the entry slug.
  
  For Example
  
  ```
  http://example.com/cat1/subcat1/entry
  
  ```
  
  Right now I have the Entry URL Format set to be `{category.first().slug}/{slug}`, but that only shows the first category. How do I access that optional `subcat1` subcategory in that field?
  
  EDIT
  
  I have tried the following but it doesn't work
  
  ```
  {category.first.slug }/{ category.first.children.first.slug ? category.first.children.first.slug ~ '/' : '' }{slug}
  
  ```
  
  I have also tried
  
  ```
  {category[0].slug}/{ category[1] ? category[1].slug ~ '/': ''}{slug}
  
  ```
  
  **Tags:** categories, url, entry-type
  
  > **Comments:**
  > **username_1**: Can you try and use double curly braces {{ .. }} , if I remember correctly there was a change in Craft 2.0 which makes them necessary.  
  > **username_0**: Just tried that, no difference unfortunately.  
  > **username_2**: It seems that you want both of the following to load the entry template:  http://example.com/cat1/subcat1/entry &  http://example.com/cat1/entry  Is this correct?  Probably you will need to use custom routes, and a bit of template logic to determine if a request segment is a category url or an entry url.    I've not run into a need for segment 1 as a category url, it has always been something like /catalog/cat/entry or news/cat/entry/  Is there a specific reason you are not doing this way?  
  > **username_0**: Because the CMS I used before – Wordpress – structures posts with subcategories in the URL in this way. To be honest it makes the most sense, otherwise what is the point of subcategories in the first place?  
  > **username_2**: So .com/cat1/ would list all entries in cat1 including its subs, and .com/cat1/sub1/ would list only sub1 entries? Then you have .com/cat1/entryA/ and .com/cat1/sub1/entryA/ ?  Craft is so flexible, you can make it behave however you need.  It will help if you update your question with more example urls and what you expect to happen with each one. :)  
  > **username_0**: It is a bit strange I agree, but the category urls I have set to `example.com/category/<category-name>/` The category slugs in the entry URL are just for contextual tips for the user & for SEO purposes... Anyways the question is how, not why :)  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_3 on 2014-06-21. Score: 18 | Accepted answer
  
  If you go into your Category Group’s settings and set the following settings:
  
  * Craft 2
    + Top Level URL Format: `{slug}`
    + Nested URL Format: `{parent.uri}/{slug}`
  * Craft 3
    + Category URI Format: `{parent.uri}/{slug}`
  
  then you would be able to set your section’s Entry URL Format to this:
  
  * Craft 2
  
    ```
    {myCategoryField.last.uri}/{slug}
  
    ```
  * Craft 3
  
    ```
    {myCategoryField.inReverse().one().uri}/{slug}
  
    ```
  
  > **Comments:**
  > **username_4**: This is handy. Is there an easy way to just output just the child category and not include the parent?  
  > **username_3**: @username_4 Not sure I’m following. Maybe post as its own question with more details?  
  > **username_4**: Ok, will post up a question shortly.  
  > **username_5**: In regards to the Category URI Format, if you have a prefix before all category URI's, the example given here for Craft 3 results in the prefix being duplicated. In this case the following solution worked for me: `prefix/{parent.slug}/{slug}` (using `parent.slug` rather than `parent.uri`).  
  > **username_6**: @username_5 - The problem with your solution prefix/{parent.slug}/{slug} is, that its only for 2 levels. The gandparent and the grand-grand-grandparent are not sluggified with this method.  Do u know what to do in this case?  
  > **username_6**: I dont really understand what this section´s Entry URL Format is.  After I changed the Category URI Format of the Category Group - I can get now 2 level URI's. Fine but what if my customer is nesting more levels.  What do u mean with section's Entry URL format? As I can see there is no section for Categories...  
  > **username_3**: @username_6 This question is asking how to set _entries’_ URLs based on their selected categories. If you are just concerned with setting category URLs, you can safely ignore the part about sections (which contain entries). The category URL format above will work no matter how many levels you have.  
  
  ---
  
  