The tag_string()
helper will display an array of tags as a string, separated by a delimiter.
Usage
<?php tag_string($recordOrTags = null, $link=null, $delimiter=', ');
Arguments
- recordOrTags - The record or array of tags you wish to display. Can be a item or other record that has tags, or it can be an array of tags. If null,
- link - The URL you wish the tag to link to. Default is null. If null, no link will be created.
- delimiter - The text to put between each tag. The default is a comma.
Examples
The following example will create a string of twenty tags, sorted alphabetically, which can then be displayed on the index.php template file in your theme, or anywhere you wish to display it. It uses the get_tags helper to get an array of tags, which is then used as the first argument for the tag_string
helper:
<?php $tags = get_tags(array('sort' => 'alpha'), 20); echo tag_string($tags, uri('items/browse')); ?>
Changing the Delimiter
Using the same example as above, we can change the delimiter to a pipe (|):
<?php $tags = get_tags(array('sort' => 'alpha'), 20); echo tag_string($tags,uri('items/browse'), ' | '); ?>