This method is intended for SQL/PostgreSQL fanatics. It does all the work in the database and prints the text using the "slugified" link. It uses Doctrine ORM only for sql call, I do not use objects. Suppose we have 10 sizes:
public function getAllForTagCloud($fontSizes = 10) { $sql = sprintf("SELECT count(tag) as tagcount,tag,slug, floor((count(*) * %d )/(select max(t) from (select count(tag) as t from magazine_tag group by tag) t)::numeric(6,2)) as ranking from magazine_tag mt group by tag,slug", $fontSizes); $q = Doctrine_Manager::getInstance()->getCurrentConnection(); return $q->execute($sql); }
then you print them with some CSS class, from .tagranking10 (best) to .tagranking1 (worst):
<?php foreach ($allTags as $tag): ?> <span class="<?php echo 'tagrank'.$tag['ranking'] ?>"> <?php echo sprintf('<a rel="tag" href="/search/by/tag/%s">%s</a>', $tag['slug'], $tag['tag'] ); ?> </span> <?php endforeach; ?>
and this is CSS :
.tagrank1{font-size: 0.3em;} .tagrank2{font-size: 0.4em;} .tagrank3{font-size: 0.5em;}
This method displays all tags. If you have a lot of them, you probably do not want the tag cloud to become a tag. In this case, you must add the HAVING TO to your SQL query:
-- minimum tag count is 8 -- HAVING count(tag) > 7
What all
danieli Jul 14 '10 at 18:19 2010-07-14 18:19
source share