Jump to content

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


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; 
}

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.