You are here:  » create category menu?


create category menu?

Submitted by tonypearce on Sun, 2011-06-26 20:29 in

Hi,
I have noticed the one thing missing (for me anyway) is a basic category menu, just a list that shows all categories in a list, has anything been done like this? I realise the standard categories listing is way advanced of this request, but then I could style and integrate into my new design.

Thanks
Tony

Submitted by support on Mon, 2011-06-27 12:01

Hi Tony,

The code for just the category list without using the A-Z display for you to display how you want is as follows:

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

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by tonypearce on Mon, 2011-06-27 13:51

Hi,

Thanks, the list appears but not as links, sorry if I did not make myself clear (a common failing, I expect everyone to be a mind reader!)
Thanks
Tony

Submitted by support on Mon, 2011-06-27 14:01

Hi Tony,

I forgot to wrap the category name in the <a> tags;

      print "<p>".$row["category"]."</p>";

...should be:

      print "<p><a href='".$href."'>".$row["category"]."</a></p>";

corrected above...

Cheers,
David.
--
PriceTapestry.com

Submitted by tonypearce on Mon, 2011-06-27 14:24

Got it, although it misses the 'category/' part out from the URL!!

Submitted by support on Mon, 2011-06-27 14:29

Sorry Tony the above code comes from categories.php and so assumes category/ if using rewrite, have a go with:

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

(corrected above also)

Cheers,
David.
--
PriceTapestry.com

Submitted by tonypearce on Mon, 2011-06-27 14:41

thats it, perfect, great support.