category total on left menu

Discussion in 'Modules / Plugins / Modifications' started by centinel3, Aug 23, 2008.

  1. centinel3 Customer

    I have read a ton of threads on how to display the total number of listings beside the category on a left menu bar and can't make any of the methods work. I have a left side menu with parent categories. All I would like to do is have the running total of each category next to the name.

    I came close to having this, though the numbers were on the top left of each text line and got a few errors to boot.

    Is there an easy way to get this to show?

    Chris
  2. Eric Barnes Guest

    Hi,

    You should be able to use this:
    Code:
    {categories_parent}
    <ul>
    {foreach from=$pcat item=entry}
    <li>{$entry.link}</li>
    {/foreach}
    </ul>
    
    Please note that this will only pull the parent categories.
  3. centinel3 Customer

    nothing happened

    I put in your code and nothing happened. No totals anywhere. When you said that only the parent categories would show totals, if there were a couple of subs in on parent category, then that parent category would show (0)? Is there a way to show totals of the parent and any and all subs?

    Here is the code that I have in the layout.tpl file thus far. I tried the code you suggested and then replaced the original back again when it didn't work.

    <div id="sidebar"> <h1>{$smarty.const.LANG_TPL_NAVIGATION}</h1>
    <ul class="sidemenu">
    {categories_parent}
    {foreach from=$pcat item=entry}
    <li>{$entry.link}</li>
    {/foreach}
    </ul>
    </div>
  4. Eric Barnes Guest

    Replace the file includes/classes/smarty/plugins/function.categories_parent.php with the code below:
    PHP:

    <?php
    /**
    * @copyright 68 Classifieds
    *
    * @author $Author: suzkaw $
    * @version $Revision: 400 $
    * @package Smarty
    * @subpackage plugins
    *
    * @Updated: $Date: 2008-08-22 15:16:17 -0400 (Fri, 22 Aug 2008) $
    */

    /**
     * This function is useful for using your parent categories in the navigation
     * 
     * To Call this function in your template you would use: 
     * <code>{categories_parent}
     * {foreach from=$pcat item=entry}
     * <ul>
     * <li>{$entry.link} {$entry.total}</li>
     * </ul>
     * {/foreach}</code>
     * 
     */

    /**
     * Include categories class
     */
    require_once(FILESYSTEM_PATH .'includes/classes/kernel/Categories.php');

    function 
    smarty_function_categories_parent($params, &$smarty)
    {
        global 
    $db$class_tpl$arr_childs;
            
            
    $Categories = new Categories;
            
    $sSQL "SELECT id,name,cLink,slug FROM ".PREFIX."categories WHERE parent_id = 0 AND display<>'N' ORDER BY cORDER DESC, name ASC";
            
    $result=$db->query($sSQL);
            
    $i=0;
            while(
    $rs=$result->fetch())
            {
                if(
    $arow['cLink']<>"")
                {
                    
    $rs['link']='<a href="'.$rs['cLink'].'">'.$rs['name'].'</a>';
                }
                else
                {
                    
    $rs['link']='<a href="category.php?cat='.$rs['slug'].'">'.$rs['name'].'</a>';
                }
                
    $arr_childs = array($rs['id']);
                
    $Categories->get_ids($arr_childs);
                
    $rs['total']=$Categories->get_count($arr_childs);
                
    $cat[]=$rs;
            }
        
    $class_tpl->assign('pcat'$cat);
    }
    ?>
    Then in your template file add:
    Code:
    {categories_parent}
    <ul>
    {foreach from=$pcat item=entry}
    <li>{$entry.link} {$entry.total}</li>
    {/foreach}
    </ul>
    
  5. centinel3 Customer

  6. Lhotch curmudgeon

    I dont have any suggestions but I just want to make you aware that doing category counts uses a lot of resources and can take a lot of time when a site starts to get busy. This can add a much dreaded delay on page loads and cause the user experience to rapidly deteriorate.

    With that in mind, all of your time and energy invested now may be wasted when your site gets busy and you want to disable the counting. Category counts used to be in the template by default but too many people complained it slowed down their sites too much.
  7. centinel3 Customer

    thank you

    Isn't that the case. You have something and people complain, then you take it away and they continue to complain about the lack of the product that they didn't like to begin with. It makes sense and I really hope to have this site buzzing with all kinds of ads. With this info, I'm going to let this one go. No numbers is fine, though I think for now I'm going to leave the totals on the subs. Thanks again for your help. Talk with you later.
    Chris
  8. Eric Barnes Guest

    Ha Ha that is so true. What is really frustrating is removing something because it caused an issue then totally forgeting about it and adding it back in later only to repeat the process.
  9. guillopuig Customer

    so its safe to say it is not recommended to try adding the totals to a left side categorie menu?
  10. Eric Barnes Guest

    Yea I wouldn't recommend it.
  11. seymourjames All Hands On Deck

    Yerr - we pulled them from our templates a while back for that reason.

Share This Page