You are here:  » Search filters


Search filters

Submitted by mikecdprice on Tue, 2011-03-01 17:20 in

Hello,

I am looking for a way to setup the site that if there are fields there in the search results when they are valid/there then would appear on the left sidebar to help the user find what they are looking for fast.

Like:

Price
Merchant
Brand
Color
Size
etc..

How hard would this be?

Something like:

{link saved}

of course it would change to show what the information is relevant to based on the category/keyword if the field information is there for the products then it would display.

So this would be an option on the search results and category as when it is totally resolved to its category link in the above example it displays the filters.

Thank you

Submitted by support on Wed, 2011-03-02 09:27

Hi Mike,

That's exactly what the sidebar filters mod available on the downloads page will do. I know you've been a user for a long time so if you want to add filters to an existing site running an earlier distribution email me your search.php and html/searchresults.php and I'll merge the changes in for you...

Cheers,
David.
--
PriceTapestry.com

Submitted by marco.saiu on Fri, 2017-12-29 17:24

Hello David,

have extensions for extra filters in the left of the site?

I have more filters and i like to add on the left of site.

Thanks,
Marco Saiu

Submitted by support on Sat, 2017-12-30 11:50

Hello Marco,

I've added a sidebar filters patch for Foundation templates - download here...

Cheers,
David.
--
PriceTapestry.com

Submitted by Erik on Fri, 2018-01-05 15:26

Hi David,

I had just configured the grid/list product view and then saw this sidebar, combining the two seemed to mess with the CSS, any recommendations on how to combine them properly?

Best,
Erik

Submitted by support on Fri, 2018-01-05 15:41

Hello Erik and welcome to the forum!

Just to confirm, is it the Foundation version of grid/list from this comment that you have implemented, and would like to merge with sidebar filters?

Cheers,
David.
--
PriceTapestry.com

Submitted by Erik on Fri, 2018-01-05 16:03

Thanks David! Figured it would be easiest to post messages directly here :)

Yes it is this one, I tried putting the sidebar together with this linked grid/list after I implemented it, I made the grid/list part into .medium-10, although it seemed like the layout got a bit mixed up.

/Erik

Submitted by support on Fri, 2018-01-05 16:12

Hi Erik,

Have a go with the following as html/searchresults.php

<?php
  if (file_exists("html/user_searchresults_before.php")) require("html/user_searchresults_before.php");
?>
<?php if(strpos($_SERVER["PHP_SELF"],"products.php")===FALSE): ?>
  <div class='row'>
  <div class='small-12 medium-2 columns'>
  <?php require("html/searchfilters_sidebar.php"); ?>
  </div>
  <div class='small-12 medium-10 columns'>
<?php else: ?>
  <div class='row'>
  <div class='small-12 columns'>
<?php endif; ?>
<style type='text/css'>
.pt_sr_center {
  text-align: center !important;
}
</style>
  <div class='row pt_sr'>
    <div class='small-12 columns'>
      <ul id='pt_sr_ul' class="small-block-grid-1 medium-block-grid-1">
        <?php foreach($searchresults["products"] as $product): ?>
          <li>
            <div class='row'>
              <div class='small-12 columns'>
                <p class='pt_sr_name'><a href='<?php print $product["productHREF"]; ?>'><?php print $product["name"]; ?></a></p>
              </div>
            </div>
            <div class='row'>
              <?php if ($product["image_url"]): ?>
              <div class='pt_sr_1 columns'>
                <p class='pt_sr_center'><a href='<?php print $product["productHREF"]; ?>'><img alt='<?php print translate("Image of"); ?> <?php print htmlspecialchars($product["name"],ENT_QUOTES,$config_charset); ?>' class='pt_fp_image' src='<?php print htmlspecialchars($product["image_url"],ENT_QUOTES,$config_charset); ?>' /></a></p>
              </div>
              <?php endif; ?>
              <div class='pt_sr_2 columns'>
                <?php if ($product["description"]): ?>
                  <p><?php print tapestry_substr($product["description"],250,"..."); ?></p>
                <?php endif; ?>
              </div>
              <div class='pt_sr_3 columns last'>
                <p class='pt_sr_center'>
                  <span class='pt_sr_from'><?php print ($product["numMerchants"]>1?translate("from")."&nbsp;":""); ?></span>
                  <span class='pt_sr_price'><?php print tapestry_price($product["minPrice"]); ?></span>
                  <br />
                  <a class='button tiny radius secondary' href='<?php print $product["productHREF"]; ?>'><?php print ($product["numMerchants"]>1?translate("Compare")." ".$product["numMerchants"]." ".translate("Prices"):translate("More Information")); ?></a>
                </p>
              </div>
            </div>
          </li>
        <?php endforeach; ?>
      </ul>
    </div>
  </div>
  <script type='text/JavaScript'>
  function pt_sr_setView(view)
  {
    $("#pt_sr_ul").removeClass("medium-block-grid-1");
    $("#pt_sr_ul").removeClass("medium-block-grid-4");
    $(".pt_sr_1").removeClass("small-12");
    $(".pt_sr_2").removeClass("small-12");
    $(".pt_sr_3").removeClass("small-12");
    $(".pt_sr_1").removeClass("medium-2");
    $(".pt_sr_3").removeClass("medium-2");
    $(".pt_sr_2").removeClass("medium-8");
    if (view=="list")
    {
      $("#pt_sr_ul").addClass("medium-block-grid-1");
      $(".pt_sr_1").addClass("small-12");
      $(".pt_sr_1").addClass("medium-2");
      $(".pt_sr_2").addClass("small-12");
      $(".pt_sr_2").addClass("medium-8");
      $(".pt_sr_3").addClass("small-12");
      $(".pt_sr_3").addClass("medium-2");
      $(".pt_sr_name").removeClass("pt_sr_center");
      $(".pt_sr_2").show();
    }
    else
    {
      $("#pt_sr_ul").addClass("medium-block-grid-4");
      $(".pt_sr_1").addClass("small-12");
      $(".pt_sr_2").addClass("small-12");
      $(".pt_sr_3").addClass("small-12");
      $(".pt_sr_name").addClass("pt_sr_center");
      $(".pt_sr_2").hide();
    }
    sessionStorage.pt_sr_view = view;
  }
  var pt_sr_view = sessionStorage.pt_sr_view;
  if (typeof pt_sr_view == "undefined") pt_sr_view = "grid";
  pt_sr_setView(pt_sr_view);
  </script>
</div>
</div>
<?php
  if (file_exists("html/user_searchresults_after.php")) require("html/user_searchresults_after.php");
?>

(I have included a fix in the above - and in the SidebarFiltersFoundation.zip download - so that the filters are not displayed when html/searchresults.php is included on the product page for Related Products...)

Cheers,
David.
--
PriceTapestry.com

Submitted by Erik on Fri, 2018-01-05 16:32

Hi David,

This looked much better!

I noticed some discrepancies I want to fix where:

- Filtering by brand is just listing all products
- Sidebar does not appear when for example viewing all products in a category, it appears when sorting by e.g. price.

Should I email you with more specific information?

Submitted by support on Fri, 2018-01-05 16:49

Hi Erik,

All sorted - there was a misplacement of the opening <form ...> tag in html/searchfilters_sidebar.php which I have corrected in the version in the download so if you first replace that file in your installation with the updated version; and also corrected is to change the sense of the check to a test not equal to "products.php" as when viewing all products in a category it is actually categories.php that is the value of $_SERVER["PHP_SELF"].

Corrected in the above html/searchresults.php, this line:

 <?php if(strpos($_SERVER["PHP_SELF"],"search.php")!==FALSE): ?>

...should be:

 <?php if(strpos($_SERVER["PHP_SELF"],"products.php")===FALSE): ?>

Cheers,
David.
--
PriceTapestry.com

Submitted by Erik on Fri, 2018-01-05 17:55

This worked! Thanks for the great help David!

/Erik

Submitted by bodybuildingcom... on Thu, 2018-01-18 08:17

Hi David,

I am wondering if something like this can still be setup with the new version of PT? At the moment I am experimenting with multiple sub directories, but I am wondering if I only install one main version if this could be done.

Basically, could specific search filters appear for one installation of PT, depending on the category searched i.e. someone is searching for mobile phones, then in the search results, specific mobile phone search filters would appear? If someone would search for photo cameras, then, photo camera search filters would appear in the search results.

I know this is easier to implement in a multi sub directory installation, as you can create search filters for each specific category installation.

I am just purely wondering if this can be done dynamically, to pull the relevant search filter depending on the category of the item searched if only one installation of PT is present?

Thanks.

Norbert

Submitted by support on Thu, 2018-01-18 11:40

Hello Norbert,

Sure - the easiest thing to do would be to create separate category relevant versions of html/searchfilters.php called, for example:

html/searchfilters_mobilephones.php
html/searchfilters_cameras.php

Then edit search.php and look for the following code at line 546:

  require("html/searchfilters.php");

...and REPLACE with:

  if ($parts[0]=="category")
  {
    switch($parts[1])
    {
      case "Mobile Phones":
        require("html/searchfilters_mobilephones.php");
        break;
      case "Cameras":
        require("html/searchfilters_cameras.php");
        break;
      default:
        require("html/searchfilters.php");
        break;
    }
  }
  else
  {
    require("html/searchfilters.php");
  }

(the above will load the default html/searchfilters.php for normal searches, or if there is no category specific version to use...)

Cheers,
David.
--
PriceTapestry.com

Submitted by bodybuildingcom... on Thu, 2018-01-18 22:19

Hi David,

Thank you for the quick response to my two questions today.

Yes, this is what I would be looking for. This should save me a ton of time.

Thanks.

Norbert

Submitted by bodybuildingcom... on Fri, 2018-01-26 15:37

Hi David,

I am wondering if the described custom search filters could be implemented into a wordpress installation as well? I am not looking for this to be implemented in the sidebar of wordpress, as I have chosen to create a grid layout for the results, an example: {link saved}

Just wondering if it is possible to have the custom search filter in the top of the wordpress results page and pull the dynamic filters like for the standalone version i.e.

html/searchfilters_mobilephones.php
html/searchfilters_cameras.php

Thanks.

Norbert

Submitted by support on Mon, 2018-01-29 10:39

Hello Norbert,

First of all it's no problem to show search filters above the results instead of as a widget - to do this, edit the plugin file pto_search.php and look for the following code at line 548:

  $html = "";

...and REPLACE with:

  $html = "";
  $html .= pto_search_filters_html();

The widget HTML is derived from the Main / Search Filters Widget template (wp-admin > Settings > PriceTapestry.org) so it would be no problem to use the same method as the above to load an alternative template from a .txt file in the html/ folder of the associated Price Tapestry installation called, for example:

html/pto_searchfilters_mobilephones.txt
html/pto_searchfilters_cameras.txt

And then to call in the alternative template (if exists) or use the default template (from /wp-admin/ > Settings > PriceTapestry.org) edit pto_search.php and look for the following code at (now) line 906:

  $html = $pto_html_search_filters_widget;

...and REPLACE with:

  global $pto_config_externalPath;
  if ($parts[0]=="category")
  {
    switch($parts[1])
    {
      case "Mobile Phones":
        $html = file_get_contents($pto_config_externalPath."html/pto_searchfilters_mobilephones.txt");
        break;
      case "Cameras":
        $html = file_get_contents($pto_config_externalPath."html/pto_searchfilters_cameras.txt");
        break;
      default:
        $html = $pto_html_search_filters_widget;
        break;
    }
  }
  else
  {
    $html = $pto_html_search_filters_widget;
  }

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by bodybuildingcom... on Tue, 2018-01-30 13:43

Hi David,

That's brilliant. I was hoping it could be done in wordpress.

Thanks.

Norbert