Tring Web Design

Specialist Web Designers in the Tring Area, Berkhamsted, Bucks and Herts - info@tring-web-design.co.uk

Sphider Tag Cloud

  • Resources
  • cPanel Website Backups
  • Creating dynamic PDF files from PHP
  • Download Limit Monitoring Using IPCOP
  • Encrypt USB drives
  • E-Mail Newsletter Design
  • Exclude my visits from Google Analytics
  • Extract, Transform and Load
  • Forum Posts
  • Glossary of Terms
  • Imaging Hard Drives
  • Installing IPCOP as a firewall
  • PHP-GTK SWK Desktop Widgets
  • Pipe emails into a PHP script
  • Pure Rounded CSS3 Corners
  • SEO Basics
  • Speed up Xubuntu Boot Time
  • Sphider Tag Cloud

  • Static header and footer from dynamic templates
  • Suckerfish CMS Made Simple menus
  • Top of Google in 5 steps
  • Website Morphing
  • Watch
  • Music & Effects
  • Syslog Firewall Analysis
  • Tools
  • This modification on Sphider, a PHP based site search engine will create a create a web2.0 style search / word / tag cloud (whatever you want to call it). I'ts not my own code, I have just modified it to work with sphider. Credit for the creator is in the code. Click here for an example of what it looks like, along with pure CSS3 rounded corners!

    Add the follwoing code to a php page, cloud.php for example:

    <style>
    #tags {
    float: left;
    width: 220px;
    margin: 10px 0px;
    padding: 10px;
    background:#ececec;
    color:#333;
    border: 1px dashed #cccccc;
    text-align: justify;
    }
    #tags .title {
    font-family:arial;
    font-size:16px;
    font-weight:bold;
    background-color: transparent;
    padding: 4px 4px;
    color:#808080;
    }
    #tags a {
    color:#39c;
    background-color: transparent;
    padding: 2px 4px;
    white-space: nowrap;
    text-decoration: none;
    font-family:arial;
    }
    #tags a:hover {
    color:#39c;
    background: green;
    text-decoration: none;
    }
    </style>
    <div id="tags">
    <div class="title">Popular Searches</div>
    <?php
    // Snippet taken from [prism-perfect.net]

    include "/path/to/public_html/search/settings/database.php";
    include "/path/to/public_html/search/settings/conf.php";

    // In the SQL below, change these three things:
    // thing is the column name that you are making a tag cloud for
    // id is the primary key
    // my_table is the name of the database table

    // added by essexboyracer:
    // dont return zero result words and limit the cloud to 10 phrases

    $query = "SELECT query AS tag, COUNT(*) AS quantity
    FROM sphider_query_log
    WHERE results > 0
    GROUP BY query
    ORDER BY query ASC
    LIMIT 10";

    $result = mysql_query($query) or die(mysql_error());

    // here we loop through the results and put them into a simple array:
    // $tag['thing1'] = 12;
    // $tag['thing2'] = 25;
    // etc. so we can use all the nifty array functions
    // to calculate the font-size of each tag
    while ($row = mysql_fetch_array($result)) {

    $tags[$row['tag']] = $row['quantity'];
    }

    // change these font sizes if you will
    $max_size = 30; // max font size in %
    $min_size = 11; // min font size in %

    // get the largest and smallest array values
    $max_qty = max(array_values($tags));
    $min_qty = min(array_values($tags));

    // find the range of values
    $spread = $max_qty - $min_qty;
    if (0 == $spread) { // we don't want to divide by zero
    $spread = 1;
    }

    // determine the font-size increment
    // this is the increase per tag quantity (times used)
    $step = ($max_size - $min_size)/($spread);

    // loop through our tag array
    foreach ($tags as $key => $value) {

    // calculate CSS font-size
    // find the $value in excess of $min_qty
    // multiply by the font-size increment ($size)
    // and add the $min_size set above
    $size = $min_size + (($value - $min_qty) * $step);
    // uncomment if you want sizes in whole %:
    // $size = ceil($size);

    // you'll need to put the link destination in place of the #
    // (assuming your tag links to some sort of details page)
    echo '<a href="/search/search.php?query='.$key.'&search=1" style="font-size: '.$size.'px"';
    // perhaps adjust this title attribute for the things that are tagged
    echo ' title="'.$value.' things tagged with '.$key.'"';
    echo '>'.$key.'</a> ';
    // notice the space at the end of the link
    }

    ?>
    </div>

    New to content management or need some help using our system? View our video tutorials

    E-mail us or complete our requirements questionnaire for a more detailed quote

    Technical resources for web designers, developers and IT professionals

    Keep up-to-date with the projects we have been involved in

    Specialist web designers in Tring, Berkhamsted, Bucks and Herts
    © Oliver Partridge trading as Tring Web Design

    info@tring-web-design.co.uk