Plugin - Category Tag Cloud

Discussion in 'Modules / Plugins / Modifications' started by Eric Barnes, Apr 1, 2008.

  1. Eric Barnes Guest

    v4 Plugin - Category Tag Cloud

    This smarty plugin will create a tag cloud of your categories.

    Requirements

    Minimum version 4.0.0

    Instructions

    Save the code below as function.categories_cloud.php and place it in the includes/classes/smarty/plugins/ folder.

    After you have saved the file you can use this code in the template file:
    Code:
    {categories_cloud} 
    You will also need to add another style to your css file. Something like this:
    Code:
    #tagcloud { margin: 0 0 20px; }
    #tagcloud a { margin: 0 5px 0 0; color: #25771F; }
    #tagcloud a:hover { background: #E7FEE5; color: #007898; }
    
    Parameters

    Below is a list of parameters you can use when calling this plugin. Please note these are optional.

    min(integer)
    The minimum size for the category with the least listings.
    max(integer)
    The maximum size for the category with the most listings.
    pixel(string)
    What size you want. Default is "em". Could be % or px.

    Download
    PHP:

    <?php
    function smarty_function_categories_cloud($params, &$smarty)
    {
        global 
    $db,$arr_childs$Categories;
        
        
    $min '.9';
        
    $max '5';
        
    $pixel 'em';
        
    $output '<div id="tagcloud">'"\n";
        
        foreach (
    $params as $_key=>$_value
        {
            switch (
    $_key
            {
                case 
    'max':
                case 
    'min':
                case 
    'pixel':
                    $
    $_key $_value;
                    break;
            }
        }
        
        
    // First get the total//
        
    $sSQL="SELECT COUNT(*) AS total FROM ".PREFIX."listings WHERE expiration > NOW() AND display = 'Y'";
        
    $result=$db->query($sSQL);
        
    $rs=$result->fetch();
        
    $total_listings=$rs['total'];
        
        
    //now loop the categories and get the percentage. 
         
    $sSQL "SELECT id,parent_id,name,slug,allowads,cLink FROM ".PREFIX."categories WHERE display<>'N' ORDER BY cORDER DESC, name ASC";
        
    $result=$db->query($sSQL);
        if(
    $result->size() > 0)
         {
            
    $i=0;
            while (
    $rs=$result->fetch())
            {
                
    $name=safeStripSlashes($rs['name']);
                
    $name=htmlspecialchars($name);
                
    //add url for category link
                
    if($rs['cLink']<>"")
                {
                    
    $start_link='<a href="'.$rs['cLink'].'">';
                }
                else
                {
                    
    $slug = ( empty($rs['slug']) ) ? $rs['id']: $rs['slug'];
                    
    $start_link='<a href="category.php?cat='.$slug.'">';
                }
                
                
    $sSQL2="SELECT COUNT(*) AS size FROM ".PREFIX."listings WHERE section = "$rs['id'] ." AND expiration > NOW() AND (display='Y' OR display='S')";
                
    $result2=$db->query($sSQL2);
                
    $row $result2->fetch();
                
    $cat_total=$row['size'];
                
    $size $cat_total $total_listings;
                
    $size $size $max;
                if(
    $size $min)
                {
                    
    $size $min;
                }
                if(
    $size $max)
                {
                    
    $size $max;
                }
                
    //output
                
    $output.='<span style="font-size: '.$size $pixel.'">'.$start_link $name .'</a></span>'"\n";
            }
            
    $result->freeResult($result);
            
    $output .= '</div>'"\n";
            return 
    $output;
         }
         else
         {
             return 
    false;
         }
    }
    ?>
  2. Maffo The Master

    Call me an idiot but what is a tag cloud?
  3. Eric Barnes Guest

    Here is an example of one: http://ajaxrain.com/tagcloud.php

    I have seen them on lots of blogs and such. So I thought it would be something someone might want.
  4. Maffo The Master

    Thanks Eric, yet another geek name to add to my vocabulary
  5. CHRD Member

    this tag cloud is listing all 420 of my cats
  6. Eric Barnes Guest

    You can just add a limit to the query:

    Code:
    FROM ".PREFIX."categories WHERE display<>'N' ORDER BY cORDER DESC, name ASC LIMIT 20";
    

  7. gppromano Customer

    I use version 3.1.5 how can I make it compatible?

    Thanks
  8. manchag Customer

    Display cities in the tag cloug

    Hello everyone,
    i'm having some problems installing this script. I followed all the steps, however all the tags look the same size:
    Enlistalo - Anuncios Clasificados en tu Localidad

    I was also wondering if it's possible to customize this script and display cities instead of categories?


    Manuel
  9. nagrap2 Customer

    Display Sub Categories Only

    Eric,

    How can I modify this script so that it only displays the Sub Categories for the Category I am viewing?

    I would want to do something similar to the following, where the user clicks on a top level category and then I display the Cloud of subcategories:

    School of Everything | Learn drawing

    Thanks in advance...
  10. damiun Customer

    Where do I have to place
    to limit the results?

    Dominick
  11. seymourjames All Hands On Deck

    How about the line which includes the categories for the query in Eric's original post. Its replacing the end of the line from what I can see.
  12. damiun Customer

    Thanks,
    But where exactly do I have to past the "limit-code" to limit the results?
    Its in the cloud ... .php file right?
  13. magicosta Customer

    Displaying only subcategories with categories_cloud plugin

    hello,

    I use the categories_cloud plugin but the problem is as users can't place any ad in main categories but just in there sub categories, I would like to display only the sub categories name. Is that possible?

    Thank you for your help

Share This Page