mad4ce
(Mad4ce)
May 26, 2011, 5:46am
1
I found out that taggable extension consist of 3 main files, I’m able to work with ETaggableBehavior.php & EARTaggableBehavior.php, but I dont know how to use ETagListWidget.php.
I’m trying to solve this because I looking for Wordpress like widget with tags (with size of tags depending on it’s usage).
Thank you for answer.
samdark
(Alexander Makarov)
May 26, 2011, 4:44pm
2
ETagListWidget isn’t a tag cloud but a simple tag list.
Adding and editing tags is working fine here, but now i want to use
<?php $this->widget('ETagListWidget'); ?>
in my _view.php
but I get a Fatal error: Call to a member function getTags() on a non-object in ETagListWidget.php on line 85
What am I doing wrong? Do I have to set more parameters?
Right now I am using
<?php echo CHtml::encode(implode(', ',$data->getTags())); ?>
to list the tags, but I also want that the separate tags are linked.
When I click a link all my news belonging to this tag should appear.
Can someone provide help?
jacmoe
(Jacob Moena)
June 9, 2011, 8:47am
4
class TagCloud extends CWidget
{
public $title='Tag Cloud';
public $maxTags=20;
protected function findTagWeights($models)
{
$total=0;
foreach($models as $model)
$total+=$model['count'];
$tags=array();
if($total>0)
{
foreach($models as $model)
$tags[$model['name']]=8+(int)(64*$model['count']/($total+<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/cool.gif' class='bbc_emoticon' alt='8)' />);
ksort($tags);
}
return $tags;
}
public function run()
{
$tags=Post::model()->getAllTagsWithModelsCount(
array(
'order'=>'count DESC',
'limit'=>$this->maxTags,
)
);
$weight = $this->findTagWeights($tags);
asort($tags);
foreach($tags as $tag)
{
if($tag['count'] >= 1) {
$link=CHtml::link(CHtml::encode($tag['name']), array('post/index','tag'=>$tag['name']));
echo CHtml::tag('span', array(
'class'=>'tagcloud',
'style'=>"font-size:".(2+$weight[$tag['name']])."pt",
), $link) . CHtml::tag('span', array('style'=>"font-size:8pt",),(($tag['count'] > 1) ? '('.$tag['count'].') ' : ' '));
}
}
}
}