User Tools

Site Tools


Sidebar

tutorials:v5_meta_tag_management:category_specific_meta

Category Specific Meta Tags in v5

<tip c w>Not Needed in Version 6.0 and up! Starting in version 6.0, we have added ability to specify the meta tags for each category on a category by category basis. Edit the specific category to see these new options for adding text to the {header_html} automatically.</tip>

Expanding on the ability above, it is possible to establish even finer-grained control over your meta tags by making them category specific, through the use of conditional statements and the built-in $category_id and $parent_categories variables.

<tip c n>Tip: You'll also need to know the category ID numbers of the categories you want to reference. These may be found in the admin, at Categories > Category Setup. They are the numbers in (parenthesis) alongside each category's name.</tip>

By way of example, suppose you wanted to set up category-specific meta tags for categories with ID numbers 11 and 12. You could replace the code in the above section (in head.tpl) with this: <tip c n>Tip: You can use this for more than just meta tags! It will work with any contents, on any part of the template, in any "main page" templates.</tip>

{if $category_id == '11'||$parent_categories.11==11}
     <meta name="Keywords" content="KEYWORDS FOR CATEGORY 11" />
     <meta name="Description" content="DESCRIPTION FOR CATEGORY 11" />
{elseif $category_id == '12'||$parent_categories.12==12}
     <meta name="Keywords" content="KEYWORDS FOR CATEGORY 12" />
     <meta name="Description" content="DESCRIPTION FOR CATEGORY 12" />
{else}
     <meta name="Keywords" content="KEYWORDS FOR REST OF SITE" />
     <meta name="Description" content="DESCRIPTION FOR REST OF SITE" />
{/if}

Note the final "else" condition in the above code: the $category_id variable only exists on pages that relate to a specific category (for example, the Category Browsing pages). If it is not present, or not equal to one of the values you specified, the "else" code will be used, so this is a good place to put generic keywords and descriptions not relating to any specific category.

Subcategory Meta Tags

The above code will also apply for any subcategory of the categories of those categories mentioned. In other words, the following would apply for any category of "category 12" if there were some and the client was currently browsing them.

{if $category_id == '12'||$parent_categories.12==12}

Extending the above example, suppose category 12 has categories 20, 21, 22 and 23 as subcategories. the above code would display the same meta tags for all five of those categories.

Now suppose you wanted categories 12, 20, 21, and 22 to have the same tags, but wanted to do something slightly different for category 23. You'd need to add a separate condition for category 23 above condition 12, like so:

{if $category_id == '11'||$parent_categories.11==11}
     <meta name="Keywords" content="KEYWORDS FOR CATEGORY 11" />
     <meta name="Description" content="DESCRIPTION FOR CATEGORY 11" />
{elseif $category_id == '23'||$parent_categories.23==23}
     <meta name="Keywords" content="KEYWORDS FOR CATEGORY 23" />
     <meta name="Description" content="DESCRIPTION FOR CATEGORY 23" />
{elseif $category_id == '12'||$parent_categories.12==12}
     <meta name="Keywords" content="KEYWORDS FOR CATEGORY 12" />
     <meta name="Description" content="DESCRIPTION FOR CATEGORY 12" />
{else}
     <meta name="Keywords" content="KEYWORDS FOR REST OF SITE" />
     <meta name="Description" content="DESCRIPTION FOR REST OF SITE" />
{/if}

The order is important here, because once a single condition is met in an if-elseif block, all other conditions that follow are skipped over, or not tested for.

<tip c n>Tip: You do not need to create specific meta tags for every single category. The above code will display the else meta tags for all categories not specified within any elseif created above it.</tip>

Getting the category name and description

As of Geo 5.1.3, there are two smarty tags available to category browsing templates that can be used to print the name and description of the current category. You can use these in conjunction with the above information on meta tags to populate the tags with category data, or elsewhere to show this information directly on the page. The tags are:

  • {$currentCategoryName} – prints the name of the current category, in the currently selected language
  • {$currentCategoryDescription} – prints the current category's description, in the currently selected language
tutorials/v5_meta_tag_management/category_specific_meta.txt · Last modified: 2014/09/25 16:55 (external edit)