<p>When setting up the category, you should be able to specify the URI Format which in your case would be "our-work/{slug}" then setting the template field to point where ever your category template is (You could point this at the same template as the overview and do a some checks but if you're beginner you'd probably better off having them in separate files).</p>

<p>Once you're loading in the new template, you need to get the projects that are related to the category by doing: </p>

<p><code>{% set projects = craft.entries.section('projects').relatedTo(category).all() %}</code></p>

CC BY-SA 4.0
2018-10-16T12:13:27.343Z
2018-10-16T12:13:27.343Z
Jamie Jenkins
<p>This may be a simple question but I am not sure how to approach it - again trying to work out best practice for these things!</p>

<p>I have a "single" at <code>/our-work</code>, which among other things displays a projects listing - basically a list of links to the full entry for that project.</p>

<p>I now wish to filter that listing by the category they are in. I also wish to update the URL to reflect that filter e.g. <code>/our-work/branding</code>.</p>

<p>I have got the below code - listing out all the projects with their links, and also outputting the category links for the filter. When the links are clicked I currently I get an error - unsurprising considering the page doesn't exist.</p>

<p>How can I best achieve both the filtering and the required url change? Any help or pointers gratefully received by a craft beginner!</p>

<pre><code>{% extends "_layouts/main" %}

{% block main %}

{% set categories = craft.categories.group('projectType').level(1).all() %}

{% for category in categories %}
  &lt;a href="/our-work/{{ category.slug }}"&gt;{{ category.title }}&lt;/a&gt;
{% endfor %}

{% for project in craft.entries.section('projects').all() %}
  &lt;a href="{{ project.url }}"&gt;
    {{ project.title }}
  &lt;/a&gt;
{% endfor %}

{% endblock %}
</code></pre>

<craft3><categories>
Filter by category and update URL
# Filter by category and update URL

(Asked by: username_0 on 2018-10-16)

This may be a simple question but I am not sure how to approach it - again trying to work out best practice for these things!
I have a "single" at /our-work, which among other things displays a projects listing - basically a list of links to the full entry for that project.
I now wish to filter that listing by the category they are in. I also wish to update the URL to reflect that filter e.g. /our-work/branding.
I have got the below code - listing out all the projects with their links, and also outputting the category links for the filter. When the links are clicked I currently I get an error - unsurprising considering the page doesn't exist.
How can I best achieve both the filtering and the required url change? Any help or pointers gratefully received by a craft beginner!
{% extends "_layouts/main" %}

{% block main %}

{% set categories = craft.categories.group('projectType').level(1).all() %}

{% for category in categories %}
  {{ category.title }}
{% endfor %}

{% for project in craft.entries.section('projects').all() %}
  
    {{ project.title }}
  
{% endfor %}

{% endblock %}

**Tags:** craft3, categories

---

## 1 answers

### Answer by username_1 on 2018-10-16. Score: 1 | Accepted answer

When setting up the category, you should be able to specify the URI Format which in your case would be "our-work/{slug}" then setting the template field to point where ever your category template is (You could point this at the same template as the overview and do a some checks but if you're beginner you'd probably better off having them in separate files).

Once you're loading in the new template, you need to get the projects that are related to the category by doing:

`{% set projects = craft.entries.section('projects').relatedTo(category).all() %}`


---

