Advertisement:

Author Topic: Need Help in Getting Categories in Sidebar  (Read 562 times)

amit

  • Newbie
  • *
  • Posts: 8
Need Help in Getting Categories in Sidebar
« on: November 29, 2014, 02:18:58 pm »
Hello ,

I've been looking to add categories in sidebar sorted by the city , i am half way done ..

Code: [Select]
function CatCountByCity($city,$catID){

                    $allCategories = array();

                    if( Category::newInstance()->isRoot($catID) ) {
                        $cat = Category::newInstance()->findSubcategories($catID);
                        if( count($cat) > 0 ) {
                            foreach($cat as $c) {
                                $allCategories[] = $c['pk_i_id'];
                            }
                        }
                    }

                    $allCategories[] = $catID ;

                    $allCats = implode(",", $allCategories);
                    $conn = getConnection();

                    $test = $conn->osc_dbFetchResult("SELECT COUNT(fk_i_item_id) as count FROM %st_item_location l JOIN %st_item i ON ( i.pk_i_id = l.fk_i_item_id AND i.fk_i_category_id IN (%s) )
 WHERE s_city = '%s'", DB_TABLE_PREFIX, DB_TABLE_PREFIX, $allCats, $city);
                    return $test['count'];
                }

added this code to the functions.php

now i need help in displaying them

Code: [Select]
<div class="widget-box">
<span>(<?php echo CatCountByRegion('osc_item_city(),osc_category_id()) ; ?>)</span>
</div>

with the help of this code i can get the number of posts in categories

Now i need to show it in side like

* category1(2)
* category2(5)

and so on .. any help ?? Thanks in advance..