3

Is there a way to create a tag cloud based on tags of channel entries be displayed using {exp:tag:entries}. In other words, tags related to the channel entries currently being displayed.

2 Answers 2

2

You'll need PHP to create first a list of entry_ids, which will then be fed to {exp:tag:tags}. Then, you will have to create a list of unique tags, which can also be done with a PHP array.

Creating a list of entry_ids based on a tag

First we'll need to create a list of entry_ids to pass into {exp:tag:tags}. Set PHP to Output:

<?php $entry_ids = ""; ?>
{exp:tag:entries tag="mockups"}
  <?php $entry_ids .= '{entry_id}|'; ?> /* concatenates entry_ids */
{/exp:tag:entries}
<?php $entry_ids = rtrim($entry_ids, '|'); ?> /* removes last pipe character */

{embed="tag/cloud" entry_ids="<?php echo $entry_ids; ?>"}

Creating a unique list of tags based on the entry_ids

In your "tag/cloud" embed (the template_group/template naming is up to you), create a unique list of tags using PHP and {exp:tag:tags}. A PHP array can be very useful to weed out duplicate data (not just here, but in many add-ons). Set PHP to Output:

<?php $tags = array(); ?>
{exp:tag:tags entry_id="{embed:entry_ids}"}
  <?php $tags['{tag_id}'] = '{tag}'; ?>
{/exp:tag:tags}

The above will result in an array with unique tags in it.

Of course, you can elaborate the above to contain more data, or even create tag hyperlinks directly as the array values.

Display the tag "cloud"

Once the tag array is complete, you can use PHP to loop through each unique tag to display them:

<h3>Tags for these entries:</h3>
<?php foreach($tags as $tag_id => $tag_name) :?>
  <?php echo $tag_name; ?><br />
<?php endforeach ?>

A similar strategy might be possible using something like Stash, but this uses the available native EE tools.

0

I think you'll want to use {exp:tag:tags}.

From the example on that page:

{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}

Does that handle what you need?

1
  • That's not exactly what I looking for. I'm trying to get a distinct list of all the tags from all the tagged channel entries displayed on a list page. Example: A users clicks a tag "mockups" and the results are 10 channel entries tagged with mockups. What I want to get on that page as well, is a single tag cloud that comes from the tags of those 10 entries. Sort of related tags, and they might look like "wireframe, prototype, planning, mockups"
    – Marc
    Commented Aug 20, 2013 at 15:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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