You are here:  » How can add the category on home page ?

Support Forum



How can add the category on home page ?

Submitted by miko77 on Wed, 2007-02-07 16:45 in

Dear Support,

Can i add the category in home page ? like Kelkoo or other comparison site ?

Submitted by support on Wed, 2007-02-07 17:04

Hello Miko,

Some users do this, it is quite easy to write.

Firstly, you need a new search form with the drop down box of categories. This file is html/searchform.php:

<div class='searchform'>
  <form name='search' action='<?php print $config_baseHREF ?>search.php'>
    <input type='text' name='q' size='35' value='<?php print (isset($q)?$q:""); ?>' />
<?php
  print "<select name='category'>";
  print "<option value=''>All Categories</option>";
  $sql = "SELECT DISTINCT(category) as category FROM `".$config_databaseTablePrefix."products` ORDER BY category";
  if (database_querySelect($sql,$rows))
  {
    foreach($rows as $row)
    {
      $selected = "";
      if (($parts[0] == "category") && ($parts[1]==$row["category"])) $selected = "selected='selected'";
      print "<option value='".$row["category"]."' ".$selected.">".$row["category"]."</option>";
    }
  }
  print "</select>";
?>
    <input type='submit' value='<?php print translate("Search"); ?>' />
  </form>
</div>

Next, you need the code at the top of search.php to redirect to the appropriate category search if a category is selected. This is the code you need to add:

  if ($_GET["category"])
  {
    $url = $config_baseHREF."search.php?q=category:".$_GET["category"].":".$_GET["q"];
    header("Location: ".$url);
    exit();
  }

Put that code right at the very top; after the PHP tags.

Hope this helps!
Cheers,
David.