I have a tag cloud code which is working fine but I would really like to limit the amount of tags shown per page. If there are more tags than the limit allows I would like to have some pagination to view the remaining tags.
Here’s my cloudtag code;
<?php
function get_tag_data() {
$result = mysql_query("SELECT * FROM tags GROUP BY tag ORDER BY count DESC");
while($row = mysql_fetch_array($result)) {
$arr[$row['tag']] = $row['count'];
}
ksort($arr);
return $arr;
}
function get_tag_cloud() {
// Default font sizes
$min_font_size = 12;
$max_font_size = 18;
// Pull in tag data
$tags = get_tag_data();
$minimum_count = min(array_values($tags));
$maximum_count = max(array_values($tags));
$spread = $maximum_count - $minimum_count;
if($spread == 0) {
$spread = 1;
}
$cloud_html = '';
$cloud_tags = array(); // create an array to hold tag code
foreach ($tags as $tag => $count) {
$replaceTag = array('_'=>'-', ' '=>'-');
$ammendTag=strtr($tag, $replaceTag);
$size = $min_font_size + ($count - $minimum_count)
* ($max_font_size - $min_font_size) / $spread;
$cloud_tags[] = '<a style="font-size: '. floor($size) . 'px'
. '" class="tag_cloud" href="http://localhost/voucherhound_v2/discountsoffers/' . $ammendTag
. '">'
. htmlspecialchars(stripslashes($tag)) . '</a>';
}
$cloud_html = join("\
", $cloud_tags) . "\
";
return $cloud_html;
}
?>
<style type="text/css">
.tag_cloud { padding: 3px ; text-decoration: none;}
.tag_cloud:link { color: #000; }
.tag_cloud:visited { color: #000; }
.tag_cloud:hover { color: #ffffff; background: #6da9eb; }
.tag_cloud:active { color: #ffffff; background: #6da9eb; }
</style>
<div id="wrapper">
<!-- BEGIN Tag Cloud -->
<?php
// Display the Tag Cloud in an HTML format
print get_tag_cloud();
?>
<!-- END Tag Cloud -->
</div>
Does anyone have any suggestions on a way of including pagination into this code? I do have a pagination code but am not sure of how to incorporate it into this code.
Pagination code;
<?php
if (isset($_GET['pageno'])) {
$pageno = $_GET['pageno'];
} else {
$pageno = 1;
} // if
$query = "SELECT count(*) FROM table WHERE ...";
$result = mysql_query($query, $db) or trigger_error("SQL", E_USER_ERROR);
$query_data = mysql_fetch_row($result);
$numrows = $query_data[0];
$rows_per_page = 15;
$lastpage = ceil($numrows/$rows_per_page);
$pageno = (int)$pageno;
if ($pageno > $lastpage) {
$pageno = $lastpage;
} // if
if ($pageno < 1) {
$pageno = 1;
} // if
$limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page;
$query = "SELECT * FROM tags $limit";
$result = mysql_query($query, $db) or trigger_error("SQL", E_USER_ERROR);
... process contents of $result ...
if ($pageno == 1) {
echo " FIRST PREV ";
} else {
echo " <a href='{$_SERVER['PHP_SELF']}?pageno=1'>FIRST</a> ";
$prevpage = $pageno-1;
echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$prevpage'>PREV</a> ";
} // if
echo " ( Page $pageno of $lastpage ) ";
if ($pageno == $lastpage) {
echo " NEXT LAST ";
} else {
$nextpage = $pageno+1;
echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$nextpage'>NEXT</a> ";
echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$lastpage'>LAST</a> ";
} // if
?>
Thanks