Tag Cloud Showing Tags for All Models
Closed this issue · 1 comments
Reported by LarryTX | November 28th, 2010 @ 04:30 PM
I' using Cake 1.3.3.
I've got several models that are Taggable. In my Post controller, for instance, I have the following statement:
$this->set('tags', $this->Post->Tagged->find('cloud', array('limit' => 20)));
In my CrochetItem controller, I have the following statement:
$this->set('tags', $this->CrochetItem->Tagged->find('cloud', array('limit' => 20)));
In my layout, I've got:
<?php if ($this->params['controller'] == 'posts') { ?>
<h1 style="color: white; font-weight: bold;">Posts Tag Cloud</h1>
<ul id="tagcloud">
<?php
echo $this->TagCloud->display($tags, array(
'before' => '<li class="fs%size% tag">',
'after' => '</li>',
'maxSize' => 50,
'minSize' => 1,
'url' => array('controller' => 'posts', 'action' => 'index'))
);
?>
</ul>
<?php } ?>
<?php if ($this->params['controller'] == 'crochet_items') { ?>
<h1 style="color: white; font-weight: bold;">Crochet Items Tag Cloud</h1>
<ul id="tagcloud">
<?php
echo $this->TagCloud->display($tags, array(
'before' => '<li class="fs%size% tag">',
'after' => '</li>',
'maxSize' => 50,
'minSize' => 1,
'url' => array('controller' => 'crochet_items', 'action' => 'index'))
);
?>
</ul>
<?php } ?>
(I know I need to clean up the PHP conditionals, but it works for now.)
When I see go to one of the Posts views, the title displays "Posts Tag Cloud," but the tag cloud displays all the tags for both Posts and Crochet Items. The same thing happens when I go to the Crochet Items views.
I'd like to have the tag cloud restricted to tags associated with the relevant model/controller. Am I doing something wrong or is this just the way the Tags plugin works?
Look at Tagged::_findCloud() If you pass 'model' => 'Post' to the find('cloud') call in the options it will filter by this model and get you only tags for posts.