How to Make a Tag Cloud?
In this tutorial i am going to show you how to create a basic tag cloud using php.I am going to write some css code to show most used tags bigger than others.
.tagcloud {float:left;width:314px; height:170px;border:8px solid #72C6FF; margin-top:10px;padding:0;}
.tagcloud ol {margin: 5px 0 5px 0px; padding: 0px 0 0px 0;}
.tagcloud ol li {display: inline;}
.tagcloud ol li a {padding: 0 3px 0 0px; margin-right: 7px; line-height: 24px;}
.tagcloud ol li a:link, .tagcloud ol li a:visited {text-decoration: none;color: blue;}
.tagcloud ol li a:hover,.tagcloud ol li a:visited:hover {background: #E6E6E9;}
.tagcloud ol li a:link span.grup, .tagcloud ol li a:visited span.grup {padding-left: 15px;}
.tagcloud ol li a.l0:hover, .tagcloud ol li a.l0 {font-size: 13px;}
.tagcloud ol li a.l1:hover, .tagcloud ol li a.l1 {font-size: 14px;}
.tagcloud ol li a.l2:hover, .tagcloud ol li a.l2 {font-size: 16px;}
.tagcloud ol li a.l3:hover, .tagcloud ol li a.l3 {font-size: 18px;}
.tagcloud ol li a.l4:hover, .tagcloud ol li a.l4 {font-size: 19px; letter-spacing: -1px;}
.tagcloud ol li a.l5:hover, .tagcloud ol li a.l5 {font-size: 20px; letter-spacing: -1px;}
.tagcloud ol li a.l6:hover, .tagcloud ol li a.l6 {font-size: 21px; letter-spacing: -1px;}
.tagcloud ol li a.l7:hover, .tagcloud ol li a.l7 {font-size: 22px; letter-spacing: -1px;}
.tagcloud ol li a.l8:hover, .tagcloud ol li a.l8 {font-size: 22px; letter-spacing: -1px;}
.tagcloud ol li a.l9:hover, .tagcloud ol li a.l9 {font-size: 22px; letter-spacing: -1px;}
Save this code as “style.css”. We have 10 different size to show tags which are used mostly. Css codes are these, however, the main problem is how to use these codes in php.The way is…
<div class="tagcloud">
<ol>
<?php
$max=??//max used tag
$min=??//min used tag
$denominator=((int)(($max-$min)/10));
$sql="SELECT * FROM category ORDER BY RAND() LIMIT 26";//tags
$result=mysql_query($sql);
while ($row=mysql_fetch_assoc($result)){
if ($denominator==0){
$level=0;
}else{
$sql="SELECT COUNT(relation_category_id) AS count_of FROM relation WHERE relation_category_id=".$row['category_id'];
$query=mysql_query($sql);
$row2=mysql_fetch_row($query);
$count_of=$row2[0];
$level=(int)($count_of/$denominator);
}
if ($level>9){$level=9;}
?><li><a href='index.php?q=<?=$row['category_id'] ?>' class='l<?=$level ?>' ><?=$row['category_name']?></a></li>
<?}?>
</ol>
</div>
We find the max used tags and min used tags after that we made $denominator=((int)(($max-$min)/10)); operation to find denominator.Than we get the tags with some sql query and print out them. Is it simple , he?
iyide bizim gibi cahilleri düşünüp google translate koysana
Comment by adem — November 19, 2009 @ 4:03 pm