This function allows you to display the tags that have been assigned to a specific channel entry. In other words, when you're viewing a channel entry, this function will show something like: Tags: peanut, acorns, pants. Please be sure NOT to name your custom tag field anything like tag or any of the other variables below, as it will conflict with the names.
{exp:tag:tags} content {/exp:tag:tags}
Parameters
The following parameters are available for use:
- backspace
- case
- dynamic
- entry_id
- limit
- orderby
- paginate
- sort
- tag_group_id
- tag_group_name
- websafe_separator
backspace=
backspace="2"
This parameter will remove that last specified amount of characters from your results. A typical usage for this would be to remove the last comma, should you choose to seperate your tags by commas.
case=
case="upper"
This parameter allows you to control the case output of the tag names. Options are upper, lower, title, sentence, or none. none (default) outputs no case modification to the tag, but strips the websafe character from multi-word tags.
dynamic=
dynamic="no"
By default, this tag will search the URI for an entry ID or URL title. This parameter allows you to disable this dynamic checking.
entry_id=
entry_id="{entry_id}"
This parameter is available should you need to hardcode a specific entry ID, or if you need to pass the entry ID through an embedded template. It is also necessary if you're using the Tag:Tags loop on a multi-entry page. Best practice is to always specify it.
limit=
limit="10"
You can limit the number of tags returned by using this parameter.
orderby=
orderby="clicks"
This parameter allows you to set a specific order to your tags. The default orderby is tag_name, which will order your tags alphabetically. Other available methods are:
- clicks - number of clicks each tag receives.
- total_entries - total number of times the tag has been assigned to channel entries.
- entry_date - date the tag was added to the system.
- edit_date - date that the tag was last used in an entry.
paginate=
paginate="both"
This parameter allows you to control where the pagination will display. Options are top, bottom, or both. Used in conjunction with the tag_paginate variable pair.
sort=
sort="asc"
This parameter allows you to control the output order. Available methods are ascending (asc) or descending (desc) order.
tag_group_id=
tag_group_id="3"
This parameter allows you to narrow down or filter the tag results in the list by specifying the tag group ID. Seperate multiples with the pipe character.
tag_group_name=
tag_group_name="group1|group2"
This parameter allows you to narrow down or filter the tag results in the list by specifying the tag group short name. Seperate multiples with the pipe character.
websafe_separator=
websafe_separator="-"
This parameter allows you to control the websafe separator character for multi-word tags generated by the websafe_tag variable. Allowable characters are +, -, and _. The default is +. Be sure to use this parameter consistently throughout your site if you change from the default value of +. For example, if you're linking to your Tag:Entries page with - as your websafe separator, you'll need to add this same parameter with - as the value for your Tag:Entries page. Otherwise results will NOT show.
Variables
The following variables are available for use:
- clicks
- tag_count
- subscribe_link
- unsubscribe_link
- tag
- tag_id
- total_entries
- tag_total_results
- websafe_tag
clicks
{clicks}
This variable will return the number of times each tag has been "clicked" (viewed in Tag:Entries loop).
tag_count
{tag_count}
This variable returns the relative position of the tag within the list of results. For example, if five tags are being displayed, then this variable will parse as 4 for the fourth tag displayed.
subscribe_link
{subscribe_link}
This variable generates a URL for subscribing to a tag. You can additionally add &return= to the URL to control the return path after the confirmation message page. An example could look like this:
<a href="{subscribe_link}&return=template_group/template">Subscribe</a>
unsubscribe_link
{unsubscribe_link}
This variable generates a URL for unsubscribing from a tag. You can additionally add &return= to the URL to control the return path after the confirmation message page. An example could look like this:
<a href="{unsubscribe_link}&return=template_group/template">Unsubscribe</a>
tag
{tag}
This variable returns the tag name.
tag_id
{tag_id}
This variable parses the ID of a given tag. This variable would normally be used when creating a link for the tag, and if your tags contain special and/or foreign characters that would cause trouble being placed in the URI.
total_entries
{total_entries}
This variable shows the total number of channel entries that are assigned to each tag.
tag_total_results
{tag_total_results}
This variable will return the total amount of tags results being displayed. You would typically use this in a conditional statement.
websafe_tag
{websafe_tag}
This variable will be replaced by a tag name where spaces have been replaced by plus signs (+). This makes the tags more safe to place in a URL and for compatibility with web apps like Reddit. You can also change the websafe seperator character by using the websafe_separator parameter.
Variable Pairs
The following variable pairs are available for use:
tag_paginate
{tag_paginate}
Page {tag_current_page} of {tag_total_pages} pages
{tag_pagination_links}
{/tag_paginate}
Pagination is available for this tag and works just like regular EE pagination, but each variable/variable pair is prepended with tag_ (except for any variables/variable pairs inside of the user_pagination_links variable pair). Used in conjunction with the paginate parameter.
Conditionals
Any of the variables above may be used as conditionals. Additionally, these exist as well:
if no_tag_results
{if no_tag_results}{/if}
This conditional can be used to display an alternate message if there are no tags that belong to that entry.
Examples
The below is a basic example of how you show the tags that belong to a channel entry:
{exp:tag:tags
entry_id="{entry_id}"
backspace="2"
orderby="tag_name"
sort="desc"
limit="10"
}
<a href="{path='articles/by_tag'}/tag/{websafe_tag}">{tag}</a>,
{/exp:tag:tags}
For the examples purpose, the articles/by_tag part should be set to a template called by_tag, or whatever you choose. Be sure to keep the tag part in the path, as that is what triggers the Tag:Entries loop to work.
You can customize the URI structure as well - refer to the Tag:Entries documentation for more information.
Below is a more advanced example of how your code might look if you want to hide "Tags:" wording and formatting around the tags list if there's NO tags for the entry:
{exp:tag:tags
entry_id="{entry_id}"
orderby="tag_name"
sort="desc"
limit="20"
}
{if tag_count == '1'}<p class="tags">Tags: {/if}
<a href="{path='articles/by_tag'}/tag/{websafe_tag}">
{tag} ({total_entries})
</a>
{if tag_count == tag_total_results}
</p>
{if:else}
,
{/if}
{/exp:tag:tags}