Answers.Body: <p>There's a lot here but I'd start by create 2 different channel <a href="http://buildwithcraft.com/docs/sections-and-entries" rel="noreferrer">sections</a>: Blog and News. </p>
  
  <p>From the front end, that makes it easy to see which entries are associated with what sections and easy to post content into each one. It also makes it easy to filter in your templates what section you're after.</p>
  
  <p>To get your entry URLs setup, it's a little tricker but you can pull it off with some Craft/Twig magic. Setup a new field, make the handle <code>blogCategory</code>, make it a Category relational field, lock it down to 1 category that pulls from your Blog Category Group, and assign it as a field to your Blog section. </p>
  
  <p><img src="https://i.sstatic.net/U2vPA.png" alt="enter image description here"></p>
  
  <p>When you're creating the channel, set the URL format in your Channel to this:</p>
  
  <pre><code>blog/{blogCategory.first().slug}/{slug}
  </code></pre>
  
  <p><img src="https://i.sstatic.net/QYRUs.png" alt="enter image description here"></p>
  
  <p>That little bit of code basically tells Craft to use the category slug of the <code>blogCategory</code>custom field we just created in part of the url and the slug of the current entry to make the url. Craft treats categories, assets, entries, etc. and other relational fields as an "array" even if you only have one selected so we need to use <code>.first()</code> to use the first one Craft sees.</p>
  
  <p>Now when you go create your blog entry, you're able to set a blog category and Craft will also use it as part of the URL.</p>
  
  <p>BTW: There's no problem routing the Blog/News index pages to a page in a structure but you have to do the heavy lifting that Craft usually automatically routes for you.</p>
  
  <p>In your _layout.html template, you could do something like:</p>
  
  <pre><code>{%if craft.request.firstSegment() is "news" %}
      {#load up news template #}
      {% include '_news/index.html' %}
  {%elseif craft.request.firstSegment() is "blog" %}
      {#load up news template #}
      {% include '_blog/index.html' %}
  {%endif%}
  </code></pre>
  
  <p>There's more to it than that, of course but hopefully that might get you started. It takes a little while to get your head around Twig and how powerful it is to use in Craft.</p>
  
  <p>You'll want to also setup URLs for your <a href="http://buildwithcraft.com/docs/categories" rel="noreferrer">Categories</a> to have Craft load the appropriate template for each. Understanding the basics of how Craft <a href="http://buildwithcraft.com/docs/routing" rel="noreferrer">routes</a> requests is helpful as well. </p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-29T08:07:02.120Z
Answers.Text: This is a really nice and complete answer and I want to add two suggestions, where you could do things a little differently. Instead of using Twig logic to include the section index templates, I'd rather just place the templates in a directory that matches the URI (→ [routing case 6](http://buildwithcraft.com/docs/routing)). And you could also make the entries load on /blog/article-slug, by leaving out the `categoriesField` part when setting up the sections' URLs and handle /blog/category-slug/article-slug like URLs with dynamic routes.
Answers.UserDisplayName: carlcs
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-29T12:23:22.833Z
Answers.Text: This is so great, thank you both, especially RitterKnight for taking all that time. After a morning of fiddling I've got a solution up and running on my site, with index pages in the Structure. I'm using carlcs's idea of having those as templates in URI-matching directories as it fits better with how I've done other things. Thanks again.
Answers.UserDisplayName: Phil Gyford
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-29T12:24:19.713Z
Answers.Text: BTW, RitterKnight - small typo: the URL format in the Channel is missing a `}`. Otherwise, great stuff.
Answers.UserDisplayName: Phil Gyford
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-29T15:03:03.343Z
Answers.Text: Thanks, typo fixed. Nice comment @carlcs,  I always forget about #6! What's great about Craft, there's multiple ways to skin the cat, the real problem sometimes ends up just choosing one!
Answers.UserDisplayName: RitterKnight
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-29T03:30:00.727Z
Answers.LastActivityDate: 2015-05-29T14:55:22.727Z
Answers.LastEditDate: 2015-05-29T14:55:22.727Z
Answers.UserDisplayName: RitterKnight
Body: <p>I have a site which has two blog-like sections, which I'll call Blog and News. Each has a few categories. The categories are different in each section. An article always has (only) 1 category assigned to it. I want the URLs to be like:</p>
  
  <pre><code>/blog/                            # index page
  /blog/category-slug               # listing all articles in category
  /blog/category-slug/article-slug  # an article
  /news/
  /news/category-slug
  /news/category-slug/article-slug
  </code></pre>
  
  <p>I'm struggling with how to construct this nicely out of Craft's Fields, Sections, Channels, Entries... I imagine I may need some custom routing, but haven't even got that far. Should I have two separate Channels and two separate Category sets? One Channel with two Entry Types and two Category sets? One Category structure with 'blog' and 'news' at the top level? How do I generate URLs for an Entry that will include <code>/news/category-slug/...</code>?</p>
  
  <p>I'm going round and round in circles. I've tried things from <a href="https://craftcms.stackexchange.com/questions/1291/how-would-i-include-the-first-category-slug-in-the-sections-entry-url-format">answers here</a> but haven't yet managed to display an entry at any URLs I expect.</p>
  
  <p>(As an added wrinkle, I want the <code>/blog/</code> and <code>/news/</code> pages to appear to the user to be pages within a separate Structure... but I was going to worry about that once I've got the basic channel/category/entry stuff working!)</p>
  
Tags: <categories><channels>
Title: Showing categories in Channel Entry URLs
ThreadText: # Showing categories in Channel Entry URLs
  
  (Asked by: username_0 on 2015-05-28)
  
  I have a site which has two blog-like sections, which I'll call Blog and News. Each has a few categories. The categories are different in each section. An article always has (only) 1 category assigned to it. I want the URLs to be like:
  
  ```
  /blog/                            # index page
  /blog/category-slug               # listing all articles in category
  /blog/category-slug/article-slug  # an article
  /news/
  /news/category-slug
  /news/category-slug/article-slug
  
  ```
  
  I'm struggling with how to construct this nicely out of Craft's Fields, Sections, Channels, Entries... I imagine I may need some custom routing, but haven't even got that far. Should I have two separate Channels and two separate Category sets? One Channel with two Entry Types and two Category sets? One Category structure with 'blog' and 'news' at the top level? How do I generate URLs for an Entry that will include `/news/category-slug/...`?
  
  I'm going round and round in circles. I've tried things from [answers here](https://craftcms.stackexchange.com/questions/1291/how-would-i-include-the-first-category-slug-in-the-sections-entry-url-format) but haven't yet managed to display an entry at any URLs I expect.
  
  (As an added wrinkle, I want the `/blog/` and `/news/` pages to appear to the user to be pages within a separate Structure... but I was going to worry about that once I've got the basic channel/category/entry stuff working!)
  
  **Tags:** categories, channels
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-05-29. Score: 12 | Accepted answer
  
  There's a lot here but I'd start by create 2 different channel [sections](http://buildwithcraft.com/docs/sections-and-entries): Blog and News.
  
  From the front end, that makes it easy to see which entries are associated with what sections and easy to post content into each one. It also makes it easy to filter in your templates what section you're after.
  
  To get your entry URLs setup, it's a little tricker but you can pull it off with some Craft/Twig magic. Setup a new field, make the handle `blogCategory`, make it a Category relational field, lock it down to 1 category that pulls from your Blog Category Group, and assign it as a field to your Blog section.
  
  ![enter image description here](https://i.sstatic.net/U2vPA.png)
  
  When you're creating the channel, set the URL format in your Channel to this:
  
  ```
  blog/{blogCategory.first().slug}/{slug}
  
  ```
  
  ![enter image description here](https://i.sstatic.net/QYRUs.png)
  
  That little bit of code basically tells Craft to use the category slug of the `blogCategory`custom field we just created in part of the url and the slug of the current entry to make the url. Craft treats categories, assets, entries, etc. and other relational fields as an "array" even if you only have one selected so we need to use `.first()` to use the first one Craft sees.
  
  Now when you go create your blog entry, you're able to set a blog category and Craft will also use it as part of the URL.
  
  BTW: There's no problem routing the Blog/News index pages to a page in a structure but you have to do the heavy lifting that Craft usually automatically routes for you.
  
  In your \_layout.html template, you could do something like:
  
  ```
  {%if craft.request.firstSegment() is "news" %}
      {#load up news template #}
      {% include '_news/index.html' %}
  {%elseif craft.request.firstSegment() is "blog" %}
      {#load up news template #}
      {% include '_blog/index.html' %}
  {%endif%}
  
  ```
  
  There's more to it than that, of course but hopefully that might get you started. It takes a little while to get your head around Twig and how powerful it is to use in Craft.
  
  You'll want to also setup URLs for your [Categories](http://buildwithcraft.com/docs/categories) to have Craft load the appropriate template for each. Understanding the basics of how Craft [routes](http://buildwithcraft.com/docs/routing) requests is helpful as well.
  
  > **Comments:**
  > **username_2**: This is a really nice and complete answer and I want to add two suggestions, where you could do things a little differently. Instead of using Twig logic to include the section index templates, I'd rather just place the templates in a directory that matches the URI (→ [routing case 6](http://buildwithcraft.com/docs/routing)). And you could also make the entries load on /blog/article-slug, by leaving out the `categoriesField` part when setting up the sections' URLs and handle /blog/category-slug/article-slug like URLs with dynamic routes.  
  > **username_0**: This is so great, thank you both, especially username_1 for taking all that time. After a morning of fiddling I've got a solution up and running on my site, with index pages in the Structure. I'm using username_2's idea of having those as templates in URI-matching directories as it fits better with how I've done other things. Thanks again.  
  > **username_0**: BTW, username_1 - small typo: the URL format in the Channel is missing a `}`. Otherwise, great stuff.  
  > **username_1**: Thanks, typo fixed. Nice comment @username_2,  I always forget about #6! What's great about Craft, there's multiple ways to skin the cat, the real problem sometimes ends up just choosing one!  
  
  ---
  
  