Jump to content

Tag Cloud database problem


richardjh

Recommended Posts

Hello again,

I need some help tweaking this function so that i can add more than one word to the 'tag' field in my sql database.

 

This function is from a tag cloud script i found on the internet and i have managed to link it to my db. However, it currently queries the db and returns tag words 'singular' - I mean i have to have one tag per row. I want to add tags using comma separators and then have this function (below) explode the comma separated list and then populate the array. I have tried (honest) but alas it has beaten me.

 

This is the function:

function get_tag_cloud() {

    // Default font sizes
    $min_font_size = 12;
    $max_font_size = 30;

    // 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) {
            $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://www.google.com/search?q=' . $tag 
            . '" title="\'' . $tag  . '\' returned a count of ' . $count . '">' 
            . htmlspecialchars(stripslashes($tag)) . '</a>';
    }
    $cloud_html = join("\n", $cloud_tags) . "\n";
    return $cloud_html;

}

 

So this function works wonderful if the 'tag' field in my database contains a single word. If i add more than one word for instance 'tag, tag2, tag3' it will show those three words as one. Thus i really want to explode then and populate the tag cloud with three separate words.

 

hope I've explained well enough for someone to help me suss where the hell i place my 'explode' function.

 

thanks gents

Link to comment
https://forums.phpfreaks.com/topic/81855-tag-cloud-database-problem/
Share on other sites

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.