You are here:  » Creating Sidebars and Sidebar Navigation/Categories


Creating Sidebars and Sidebar Navigation/Categories

Submitted by redmosquito on Fri, 2011-01-28 12:29 in

Hi

I am completely new to PT and am finding my way around the forum. I was wondering if there is an up to date thread or info you could offer on how to create sidebars and include category navigation in the side bars.

Thanks

JD

Submitted by support on Fri, 2011-01-28 12:58

Hi JD,

The basics of creating sidebars for your site are described in this post (left-hand sidebar) and this post (left and right-hand sidebar). This is achieved by creating 2 new files in your /html/ folder that enclose the Price Tapestry generated content by your own left and / or right hand column content.

I don't normally recommend a dynamic category navigation in the sidebar for general sites as the list can be very large and it's inefficient to have the query run for every page view of your home page, but it's perfectly acceptable for niche sites.

Firstly, to create a manual category navigation, you can simply create a list of links directly to the category search results pages on your site. These links depend on whether or not you have set up clean URLs using .htaccess and having set $config_useRewrite = TRUE in your config.php. If you have, then your category URLs are

/category/Category-Name/

Otherwise, they would be:

/search.php?q=category:Category+Name

So, to create a manual list of category navigation links, and assuming using rewrite (clean URLs), add the following code where the "insert your left/right column code here..." comment appears:

<ul>
  <li><a href='/category/Category-1/'>Category 1</a></li>
  <li><a href='/category/Category-2/'>Category 2</a></li>
  <li><a href='/category/Category-3/'>Category 3</a></li>
</ul>

However, if you would like to try creating a dynamic category index, add the following PHP code at the same point:

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

Hope this helps!

Cheers,
David.
--
PriceTapestry.com