You are here:  » how to add to custom fields into search sidebar filter


how to add to custom fields into search sidebar filter

Submitted by technoarenasol on Sat, 2012-09-29 17:16 in

I am create new gender custom field .now i want to add this field into sidebar .

please note I am use sidebar with grid/list view

Submitted by support on Mon, 2012-10-01 07:43

Hi,

Code for the filters is contained within search.php and html/searchresults.php - what I suggest is to take "categoryFilter" as a template and replicate every section of code relating to "categoryFilter" for your new "genderFilter" - e.g. replacing "category" with "gender" in each copied section.

For example, in search.php the first copy would be this new line:

  $genderFilter = ($_GET["genderFilter"]?$_GET["genderFilter"]:"");

...and in html/searchresults.php the first copy would be this new section:

  $sql1 = "SELECT DISTINCT(gender) FROM `".$config_databaseTablePrefix."products` WHERE ".$where." AND gender <> '' ORDER BY gender";
  if (database_querySelect($sql1,$rows1))
  {
    print "<label form='cf'>By gender:</label><br />";
    print "<select style='width:150px;' id='cf' name='genderFilter'>";
    print "<option value=''>All</option>";
    foreach($rows1 as $row)
    {
      $selected = ($_GET["genderFilter"]==$row["gender"]?"selected='selected'":"");
      print "<option value='".htmlentities($row["gender"],ENT_QUOTES,$config_charset)."' ".$selected.">".$row["gender"]."</option>";
    }
    print "</select>";
    print "<br /><br />";
  }

If you're not sure what other sections of code to copy just let me know!

Cheers,
David.
--
PriceTapestry.com

Submitted by technoarenasol on Mon, 2012-10-01 15:20

technoarenasol
thanks david for reply

but i didn't understand what exactly i have to do

what other section i have to modify
does i have to copy each code where categoryFilter comes and then replace the gender in place of category
can you please tell in detail because i need to add more new filter in future.

thanks

Submitted by support on Mon, 2012-10-01 15:36

Hi technoarenasol,

In html/searchresults.php it is actually only the modification described above - but in search.php I suggest using categoryFilter as a template, and whenever you add a new filter COPY each of the following sections, and then PASTE back in on the next line but replacing "category" with "gender" or the name of the new filter you are adding. It must match the name of the new field that you added to the database....

The following line numbers are based on the SidebarFilters.zip version of search.php:

Line 16:

  $categoryFilter = ($_GET["categoryFilter"]?$_GET["categoryFilter"]:"");

Lines 57-61:

  if ($categoryFilter)
  {
    $priceWhere .= " AND category = '".database_safe($categoryFilter)."' ";
  }

Lines 317-320:

      if ($categoryFilter)
      {
        $sortHREF .= "categoryFilter=".urlencode($categoryFilter)."&amp;";
      }

Lines 410-413:

    if ($categoryFilter)
    {
      $sort .= "&amp;categoryFilter=".urlencode($categoryFilter);
    }

Cheers,
David.
--
PriceTapestry.com

Submitted by technoarenasol on Mon, 2012-10-01 17:50

Hi David,thanks for replay but i am not find above in search.php

This is my search.php file
{code saved}

Submitted by support on Tue, 2012-10-02 09:44

Hi,

I just forwarded to you by email a copy of your search.php with support for genderFilter - if you're not sure about the corresponding modifications to html/searchresults.php if you would like to reply with that file as an attachement I'll add the code for you...

Cheers,
David.
--
PriceTapestry.com

Submitted by shubi on Tue, 2022-02-08 09:07

Hey, I was wondering would this solution still work or would there need to be changes to it?

Submitted by support on Wed, 2022-02-09 09:26

Hi,

This was for a much earlier version of Price Tapestry but you can download a sidebar filters mod for the Foundation template using this link...

Cheers,
David.
--
PriceTapestry.com