This is a common question and similar responses have been provided in other threads, which are good reads to get some inspiration:
We have also (recently) added a page in our Solspace Solutions section on the subject:
http://support.solspace.com/solution/articles/4000047779-create-a-list-of-all-unique-tags-from-a-entries-list
A summary here, with modifications for Favorites:
To get a list of tags from specific entries in one list, and without tags being repeated (i.e. display a list of unique tags), {exp:tag:cloud}
can't be used because there is no entry_id=""
parameter.
Because {exp:tag:tags}
is repeated at each {exp:channel:entries}
(or {exp:favorites:entries}
) loop, chances are you get duplicates of some tags. You'll need to create an array of unique tags to filter out duplicates. One way to do this is with PHP.
Enable PHP in your Templates and set it to Output. Then create your array:
{!-- Start with an empty array --}
<?php $tags = array(); ?>
{exp:favorites:entries /* your parameters */}
{exp:tag:tags entry_id="{entry_id}"}
{!-- add the tag to the array. Duplicate tag_ids will be filtered this way --}
<?php tags['{tag_id}'] = '{tag_name}'; ?>
{exp:tag:tags}
{exp:favorites:entries}
Now your $tags
array should have unique keys (the tag_id
), and therefore tag_names should be unique as well. Finally, simply loop through the unique list of tags outside of and after {exp:favorites:entries}
. Below we're building a comma-separated list first, then trimming the final comma. Finally, we output the final string:
{!-- Start with an empty string --}
<?php $tag_list = ''; ?>
<?php foreach($tags as $tag) :?>
{!-- Concatenate tags --}
<?php $tag_list .= $tag . ", "; ?>
<?php endforeach ?>
{!-- Trim the final extra comma and display to screen --}
<?php echo rtrim($tag_list, ", "); ?>
There are likely other ways to do this, using Stash perhaps, but this uses native tools in EE.