Jump to content

[SOLVED] tag cloud ... help please b4 I shoot myself ...


imarockstar

Recommended Posts

Ok I have posted this b4 . well sortof .... I changed my code and its still not working ... so I starting from fresh ...

 

This is what I want the TAG CLOUD to do.

 

I want the tag cloud to pull the tags ($tag) and the tags description ($desc) from the database and display them on the front page of my site. As of right now it is only pulling the tag ($tag) and the tag count ($count)

 

As you can see there are two (2) fuctions that make up this tag cloud :

 

function tag_info() { 
  $result = m_q("SELECT * FROM pic_tags GROUP BY tag ORDER BY RAND() LIMIT 20"); 
  while($row = mysql_fetch_array($result)) {
  	// add both data to returned array
    $arr[$row['tag']] = array($row['count'], $row['desc']);
  } 
  ksort($arr); 
  return $arr; 
}

function tag_cloud() {

    $min_size = 10;
    $max_size = 30;

    $tags = tag_info();

foreach ($tags as $t) $tags1[] = $t[0];
$minimum_count = min($tags1);
$maximum_count = max($tags1);

    $spread = $maximum_count - $minimum_count;

    if($spread == 0) {
        $spread = 1;
    }

    $cloud_html = '';
    $cloud_tags = array();
    foreach ($tags as $tag => $count) {
        $size = $min_size + ($count[0] - $minimum_count) 
            * ($max_size - $min_size) / $spread;
        //change output to $count[0](count) and $count[](description)
        //add ending a tag
        $cloud_tags[] = '<a style="font-size: '. floor($size) . 'px' 
            . '" class="tag_cloud" title=" '. $desc .'   " href="tagedphoto.php?tag=' . $tag 
            . ' ">' 
            . htmlspecialchars(stripslashes($tag)) . '</a>';
    }
    $cloud_html = join("\n", $cloud_tags) . "\n";
    return $cloud_html;
}

 

 

As  you can see by the code, I am trying to display the tag ($tag) description ($desc) within the title attribute of the link.

 

Can anyone tell me what I am doing wrong ?

 

here is the link to the working tag cloud ..

 

http://franklinspirko.com/sites/dwf/

 

this section:

 

    foreach ($tags as $tag => $count) {
       $size = $min_size + ($count[0] - $minimum_count) 
           * ($max_size - $min_size) / $spread;
       //change output to $count[0](count) and $count[](description)
       //add ending a tag
       $cloud_tags[] = '<a style="font-size: '. floor($size) . 'px' 
           . '" class="tag_cloud" title=" '. $desc .'   " href="tagedphoto.php?tag=' . $tag 
           . ' ">' 
           . htmlspecialchars(stripslashes($tag)) . '</a>';
   }

 

uses $desc, but it hasn't been assigned anywhere.  substitute $count[1] for $desc in that block.

so what would change here

 

function tag_info() { 
  $result = m_q("SELECT * FROM pic_tags GROUP BY tag ORDER BY RAND() LIMIT 20"); 
  while($row = mysql_fetch_array($result)) {
  	// add both data to returned array
    $arr[$row['tag']] = array($row['count'], $row['desc']);
  
  } 
  ksort($arr); 
  return $arr; 
}

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.