You are here:  » Show categories on index page

Support Forum



Show categories on index page

Submitted by weztcoazt on Tue, 2008-07-22 19:45 in

Greetings,
I am trying to get my categories to show on the index page, so I added this bit of code to it.

 <?php
  $atoz["items"] = array();
  $sql = "SELECT DISTINCT(category) as category FROM `".$config_databaseTablePrefix."products` ORDER BY category";
  if (database_querySelect($sql,$rows))
  {
    foreach($rows as $product)
    {
      if ($product["category"])
      {
        $item = array();
        $item["name"] = $product["category"];
        if ($config_useRewrite)
        {
          $item["href"] = tapestry_hyphenate($product["category"])."/";
        }
        else
        {
          $item["href"] = "search.php?q=category:".urlencode($product["category"]).":";
        }
        $atoz["items"][] = $item;
      }
    }
  }
  require("html/atoz.php");
  print "<br clear='all'>";
  ?>

Which looks GREAT, but the category links are linking into a different folder which is causing an error. Any ideas on how I can make this work?

Submitted by support on Wed, 2008-07-23 04:18

Hi,

It should just be a case of prefixing category/ infront of the value; so instead of:

        if ($config_useRewrite)
        {
          $item["href"] = tapestry_hyphenate($product["category"])."/";
        }

Use:

        if ($config_useRewrite)
        {
          $item["href"] = $config_baseHREF."category/".tapestry_hyphenate($product["category"])."/";
        }

That should do the trick...

Cheers,
David.

Submitted by weztcoazt on Wed, 2008-07-23 14:41

Excellent, worked perfectly

Big thanks from a NON developer trying to tweak this script to make it look unique!

Ian