1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

total_listings plugin amendment (if poss)

Discussion in 'Templates, HTML, CSS, and Design Help' started by jason1971, Mar 3, 2010.

  1. jason1971 Customer

    Hi all,

    Would it be possible to create a copy of the plugin {total_listing} to only show the number of listings for a certain catergory either via category name or category id ?, as the code is short i have copied it here, but as usual im not sure what to put where so any help gratefully received Jason

    * @param return int Total number.
    */
    function smarty_function_total_listings($params, &$smarty)
    {
    global $db;

    $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'];

    return $total_listings;
    }
  2. Eric Barnes Guest

    You can try something like this:
    PHP:

    function smarty_function_total_listings($params, &$smarty)
    {
        global 
    $db;
        
        
    $category '';
        
        foreach (
    $params as $_key=>$_value
        {
            switch (
    $_key
            {
                case 
    'category':
                    $
    $_key = (int)$_value;
                    break;
            }
        }
        
        
    $sSQL="SELECT COUNT(*) AS total FROM ".PREFIX."listings WHERE expiration > NOW() AND display = 'Y'";
        if (
    $category != '')
        {
            
    $sSQL .= ' AND section = '$category;
        }
        
    $result=$db->query($sSQL);
        
    $rs=$result->fetch();
        
    $total_listings=$rs['total'];

        return 
    $total_listings;
    }
    Then in your template:
    Code:
    {total_listings category=1}
  3. jason1971 Customer

    HI Eric,

    I tried as you suggested but it isnt working, it just blanks out the whole page, any other thoughts ?

    By the way thanks for the help

    Jason
  4. Eric Barnes Guest

    Make sure in the plugin file you but that function inside <?php ?> tags. That wasn't included in the sample.
  5. jason1971 Customer

    Hi Eric,

    Many many thanks got it sorted thanks to you.

    Regards

    Jason

Share This Page