0

I have a template for categories and I am trying to get the catgeory name in the meta title of the page (or anywhere on the page).

I thought it was just as simple as

<title>{category_name} &ndash; {site_name}</title>

But it's not. I've tried trying to find my answer but to no avail.

1

There are different ways of create a category page.

If you're using the "default" way, the Channel Category Heading Tag can help you:

{exp:channel:category_heading}
    <title>{category_name} &ndash; {site_name}</title>
    {if category_description}
        <meta name="description" content="{category_description}" />
    {/if}
{/exp:channel:category_heading}

Remember to not put it inside a Channel Entries tag.

The Category ID needs to be in the URL. Or the Category URL Indicator and the category URL title.

3
  • Thanks, I've just tried to implement that but it's not working. Here's my code: pastebin.com/PE9ZtAqk And have I called the page the right thing? Screenshot of the template screen: s4.postimg.org/3kyuwen9p/Template_Manager_Expression_Engine.png – drew.deakin Aug 20 '16 at 6:33
  • Your segments must match a valid category - what are your segments on the URL you're trying to access and get results on? – Peter Lewis Aug 20 '16 at 8:09
  • @drew.deakin, so get the category name is just one of your problems. I gonna update my answer. – Sobral Aug 20 '16 at 15:50
0

If you are not using category ID's in the category page URL
example: www.websitename/blog/category/events

Code for category template:

{if segment_2 == 'category'}

{!-- code for showing category title on pages not using URL category ID's --}
  {exp:channel:categories channel='blog' style='linear'}                     
    {if category_url_title == segment_3}
      {category_name}
    {/if}
  {/exp:channel:categories}

{!-- fallback for pages using URL category ID's example: /blog/category/C4 --}  
  {exp:channel:category_heading}
    {category_name}
  {/exp:channel:category_heading}

{/if}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.