<p>This is the solution:</p>

<pre><code>{% set category = craft.categories.slug(craft.request.getParam('category')).first() %}
</code></pre>

CC BY-SA 3.0
2018-03-17T06:39:26.483Z
This seems to only take the first category page. How would I get the category that is related to the current page I'm on, like, If this page has a category related to it, display that category title and link? Thanks @BradBell
mateostabio
CC BY-SA 3.0
2017-03-15T09:48:57.800Z
2017-03-15T22:07:33.620Z
2017-03-15T22:07:33.620Z
MGX
<p>It depends how you're fetching the category. But if you've defined the template when setting up the categories it would be called be within a var called 'category', which would be a category object. You should then be able to access it using:</p>

<pre><code>{{ category.title }}
</code></pre>

<p>If, on the other hand, you were getting the category via a slug in the URL, you would do something like:</p>

<pre><code>{% set category = craft.categories.group('productType').slug(craft.request.lastSegment).first %}
{{ category.title }}
</code></pre>

<p>UPDATE: Following on from your updated question, you've already got the category as an object so there is no need to get it again. Try replacing:</p>

<pre><code>// THIS IS YOUR LOOP, BTW
{% for category in craft.categories.group('productType').find() %}       
    &lt;header class="flush"&gt;&lt;h1&gt;{{ category.title }}&lt;/h1&gt;&lt;/header&gt; 
{% endfor %}
</code></pre>

<p>with:</p>

<pre><code>{{ category.title }}
</code></pre>

<p>But you might need to add a conditional in case the page is loaded without a category. Something like:</p>

<pre><code>{% if category | length %}
    {{ category.title }}
{% endif %}
</code></pre>

CC BY-SA 3.0
2017-03-14T09:58:45.250Z
Many thanks for your response Clive - much appreciated.
Still struggling to get this to work....have amended code in original question (sorry - should have included this in my original post) :(
MGX
CC BY-SA 3.0
2017-03-14T16:20:08.410Z
Many thanks for your response Clive - much appreciated.
I tried both those alternatives - but unfortunately, they just output nothing/blank for the Category Title.
MGX
CC BY-SA 3.0
2017-03-15T10:01:54.360Z
What does `{{ craft.request.getParam('category') }}` output? And didn't you have `.first` on the end of your initial `craft.categories` query before?
Clive Portman
CC BY-SA 3.0
2017-03-15T13:25:38.380Z
I added that extra bit early today as it's the solution - apologies if I didn't make that clear!
MGX
CC BY-SA 3.0
2017-03-16T08:59:31.800Z
Cool. You should accept MGX's answer below, as it better answers the question in it's current form.
Clive Portman
CC BY-SA 3.0
2017-03-13T17:46:53.963Z
2017-03-14T14:36:55.473Z
2017-03-14T14:36:55.473Z
Clive Portman
<p>I need to be able to display the Category Title of a single category (as a h1 tag for a page displaying a list of the entries for that category).  I can successfully display the relevant entries for the category on the page, but when I have tried to display the category title it displays all of the categories titles (in a loop), not just the single category title.</p>

<p>My code:</p>

<pre><code>{% if craft.request.getParam('category') is not null %}    

        {% set category = craft.categories.slug(craft.request.getParam('category')) %}

        {% set products =  craft.entries.section('products').relatedTo(category).find() %}


        {% else %}
               {% set products = craft.entries.section('products').find() %}
        {% endif %}



&lt;div class="top-title"&gt; 

     {% for category in craft.categories.group('productType').find() %}       
        &lt;header class="flush"&gt;&lt;h1&gt;{{ category.title }}&lt;/h1&gt;&lt;/header&gt; 
     {% endfor %}
</code></pre>

<p>Any help would be very much appreciated!
Many thanks!</p>

<category>
How do I display the Category Title?
# How do I display the Category Title?

(Asked by: username_0 on 2017-03-13)

I need to be able to display the Category Title of a single category (as a h1 tag for a page displaying a list of the entries for that category).  I can successfully display the relevant entries for the category on the page, but when I have tried to display the category title it displays all of the categories titles (in a loop), not just the single category title.
My code:
{% if craft.request.getParam('category') is not null %}    

        {% set category = craft.categories.slug(craft.request.getParam('category')) %}

        {% set products =  craft.entries.section('products').relatedTo(category).find() %}


        {% else %}
               {% set products = craft.entries.section('products').find() %}
        {% endif %}



 

     {% for category in craft.categories.group('productType').find() %}       
        {{ category.title }} 
     {% endfor %}

Any help would be very much appreciated!
Many thanks!

**Tags:** category

---

## 2 answers

### Answer by username_0 on 2017-03-15. Score: 3 | Accepted answer

This is the solution:
{% set category = craft.categories.slug(craft.request.getParam('category')).first() %}

> **Comments:**
> **username_1**: This seems to only take the first category page. How would I get the category that is related to the current page I'm on, like, If this page has a category related to it, display that category title and link? Thanks @BradBell  

---

### Answer by username_2 on 2017-03-13. Score: 4

It depends how you're fetching the category. But if you've defined the template when setting up the categories it would be called be within a var called 'category', which would be a category object. You should then be able to access it using:
{{ category.title }}

If, on the other hand, you were getting the category via a slug in the URL, you would do something like:
{% set category = craft.categories.group('productType').slug(craft.request.lastSegment).first %}
{{ category.title }}

UPDATE: Following on from your updated question, you've already got the category as an object so there is no need to get it again. Try replacing:
// THIS IS YOUR LOOP, BTW
{% for category in craft.categories.group('productType').find() %}       
    {{ category.title }} 
{% endfor %}

with:
{{ category.title }}

But you might need to add a conditional in case the page is loaded without a category. Something like:
{% if category | length %}
    {{ category.title }}
{% endif %}

> **Comments:**
> **username_0**: Many thanks for your response Clive - much appreciated. Still struggling to get this to work....have amended code in original question (sorry - should have included this in my original post) :(  
> **username_0**: Many thanks for your response Clive - much appreciated. I tried both those alternatives - but unfortunately, they just output nothing/blank for the Category Title.  
> **username_2**: What does `{{ craft.request.getParam('category') }}` output? And didn't you have `.first` on the end of your initial `craft.categories` query before?  
> **username_0**: I added that extra bit early today as it's the solution - apologies if I didn't make that clear!  
> **username_2**: Cool. You should accept MGX's answer below, as it better answers the question in it's current form.  

---

