Question

I'd like to create a tag clouds, and I'm wondering based on what parameters I should do this.

Also, I don't want the same top tags to be displayed all the time, so how do big sites handle this?

I've got table that contains the items, a table that contains the tags (just tag id and tag text) and another table for normalization, with a row for each relationship between an item and a tag.

Was it helpful?

Solution

I think a good implementation with nice flexibility (and in PHP) is WordPress's implementaion. Have a look at their argument object in the documentation for wp_tag_cloud():

  • smallest - The smallest tag (lowest count) is shown at size 8
  • largest - The largest tag (highest count) is shown at size 22
  • unit - Describes 'pt' (point) as the font-size unit for the smallest and largest values
  • number - Displays at most 45 tags
  • format - Displays the tags in flat (separated by whitespace) style
  • separator - Displays whitespace between tags
  • orderby - Order the tags by name
  • order - Sort the tags in ASCENDING fashion
  • exclude - Exclude no tags
  • include - Include all tags
  • *topic_count_text_callback* - Uses function default_topic_count_text
  • link - view
  • taxonomy - Use post tags for basis of cloud
  • echo - echo the results

That's with this code as a sample:

<?php $args = array(
    'smallest'                  => 8, 
    'largest'                   => 22,
    'unit'                      => 'pt', 
    'number'                    => 45,  
    'format'                    => 'flat',
    'separator'                 => \"\n\",
    'orderby'                   => 'name', 
    'order'                     => 'ASC',
    'exclude'                   => null, 
    'include'                   => null, 
    'topic_count_text_callback' => default_topic_count_text,
    'link'                      => 'view', 
    'taxonomy'                  => 'post_tag', 
    'echo'                      => true ); ?>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top