我有以下数组:
$artist = array("the roots", "michael jackson", "billy idol", "more", "and more", "and_YET_MORE");
$count = array(5, 3, 9, 1, 1, 3);我想生成一个标签云,它将有较高数量的艺术家在$count中封装在h6标签和最低的封装h1标签中。
发布于 2010-05-31 19:53:58
你也需要添加一个对数函数到它上面。(摘自tagadelic,我的创建标签云http://drupal.org/project/tagadelic的Drupal模块):
db_query('SELECT COUNT(*) AS count, id, name FROM ... ORDER BY count DESC');
$steps = 6;
$tags = array();
$min = 1e9;
$max = -1e9;
while ($tag = db_fetch_object($result)) {
$tag->number_of_posts = $tag->count; #sets the amount of items a certain tag has attached to it
$tag->count = log($tag->count);
$min = min($min, $tag->count);
$max = max($max, $tag->count);
$tags[$tag->tid] = $tag;
}
// Note: we need to ensure the range is slightly too large to make sure even
// the largest element is rounded down.
$range = max(.01, $max - $min) * 1.0001;
foreach ($tags as $key => $value) {
$tags[$key]->weight = 1 + floor($steps * ($value->count - $min) / $range);
}然后在您的视图或模板中:
foreach ($tags as $tag) {
$output .= "<h$tag->weight>$tag->name</h$tag->weight>"
}发布于 2008-08-01 23:10:57
从我的脑海中...
$artist = array("the roots","michael jackson","billy idol","more","and more","and_YET_MORE");
$count = array(5,3,9,1,1,3);
$highest = max($count);
for (int $x = 0; $x < count($artist); $x++)
{
$normalized = $count[$x] / $highest;
$heading = ceil($normalized * 6); // 6 heading types
echo "<h".$heading.">".$artist[$x]."</h".$heading.">";
}发布于 2008-08-03 13:01:24
也许这有点学术和离题,但是由于文档结构和诸如此类的原因,hX标记可能不是标记云的最佳选择。
也许是具有适当类属性的spans或ol (加上一些CSS)?
https://stackoverflow.com/questions/227
复制相似问题