indexu.com

developer blog

Custom category listing in browse.html

In earlier post, I show you how to create custom category listing in front page. Now will show you how to create custom category listing in category pages (browse.html). The real challenge here is to construct the category path as we are deep inside category level.

First, you need to remove this tag from browse.html

<%$category%>

Then replace with the following codes

<%php%>
  global $dbConn, $indexu, $cat;
 
  $img_path = $indexu->config['site_url'].'/themes/'.$indexu->config['active_theme'].'/cat';
 
  $query = "select category_id, name, image
            from idx_category
            where parent_id = '$cat'";
  $result = $dbConn->Execute($query);
 
  $limit = $result->RecordCount();
  $i=0;
 
  while ($row = $result->FetchRow()) {
    $i++;
 
    // here we construct the category url, need to fetch the parents
 
    $parents = $dbConn->Lookup('parents', 'idx_category_path', "category_id = '{$row['category_id']}'");
    $arr = explode(';',$parents);
    array_pop($arr);
    array_pop($arr);
    array_shift($arr);
    array_reverse($arr);
 
    unset($path);
 
    foreach ($arr as $k => $v) {
      $name = $dbConn->Lookup('name', 'idx_category', "category_id = '$v'");
      $path .= SEOReplace($name).'/';
    }
 
    $url = $path.SEOReplace($row['name']).'/';
    print "<div class='subList'><a href='$url'>{$row['name']}</a></div> \n";
  }
<%/php%>