You are here:  » Using Categories in a sidebar as navigation

Support Forum



Using Categories in a sidebar as navigation

Submitted by npaitken on Wed, 2008-07-09 11:40 in

I'd like to create a Sidebar Navigation using Categories. A couple of questions:

1) How is this done?
2) If I use category mapping, will the master category be listed in my navigation?

Thanks,
Neil

Submitted by support on Wed, 2008-07-09 12:54

Hi Neil,

Category mapping is applied at import so anything you do to feature a category list on your site will include the mapped categories as these are what are in the database.

Firstly, if you don't yet have a layout that includes a fixed menu to the left, check the code in the following thread for ideas....

http://www.pricetapestry.com/node/565

Now with regards to including a list of categories within the menu area; if you have a very large site (several thousand products), the query to generate the category list on every single page view could slow the site down unacceptably. Instead, what I normally recommend is to hard code links to the required category pages directly into the HTML, for example:

<ul>
<li><a href='/search.php?q=category:Electrical:'>Electrical</a></li>
<li><a href='/search.php?q=category:Gardening:'>Gardening</a></li>
<li><a href='/search.php?q=category:Home:'>Home</a></li>
</ul>

If you want to try a dynamic list, the following is the PHP code that you need, but watch out for performance aspects if you do this:

<?php
  $sql 
"SELECT DISTINCT(category) as category FROM `".$config_databaseTablePrefix."products` ORDER BY category";
  if (
database_querySelect($sql,$rows))
  {
    print 
"<ul>";
    foreach(
$rows as $row)
    {
       print 
"<li><a href='".$config_baseHREF."search.php?q=category:".urlencode($row["category"]).":'>".$row["category"]."</a></li>";
    }
    print 
"</ul>";
 }
?>

Cheers,
David.