You are here:  » Switch between grid and List view

Active Forum Topics


Switch between grid and List view

Submitted by technoarenasol on Wed, 2012-09-12 18:01 in

Hello

I want to Display search result in List and Grid View. I want to put Icon Button for switching.How can be possible.

Submitted by support on Wed, 2012-09-12 18:51

Hi,

[Edit: scroll down for updated Responsive HTML (Foundation) template version]

I've just posted a new version of the grid view mod to the download extras page. Select the file SearchResultsGridList.zip, which contains modified versions of search.php and html/searchresults.php with a text link to switch between views.

To convert the text link to icons; within the modified search.php look for the following code at line 329:

  $viewText = "<a href='".$viewHREF."'>".translate("List View")."</a>";

...and REPLACE with:

  $viewText = "<a href='".$viewHREF."'><img border='0' src='".$config_baseHREF."images/listview.gif' /></a>";

...and finally the following code at line 335:

  $viewText = "<a href='".$viewHREF."'>".translate("Grid View")."</a>";

...and REPLACE with:

  $viewText = "<a href='".$viewHREF."'><img border='0' src='".$config_baseHREF."images/gridview.gif' /></a>";

Before uploading, create your icon images as

images/listview.gif
images/gridview.gif

You can adjust the number of columns in grid view in html/searchresults.php at line 8:

  $columns = 3;

...and don't forget to update $config_resultsPerPage in config.php (line 20) to be an exact multiple of the number of columns; for example if using 3 columns then use either 9 or 12 etc.

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by technoarenasol on Thu, 2012-09-13 18:16

technoarenasol

Thanks David.Code working But searchFilter Sidebar not Display now

Submitted by support on Fri, 2012-09-14 06:41

Hi technoarenasol,

I'll email you a combined version of html/searchresults.php with both the list filters (with direct links) and grid/list view search results - please check your email in a few minutes...

Cheers,
David.
--
PriceTapestry.com

Submitted by technoarenasol on Fri, 2012-09-14 14:05

technoarenasol

Hi David

now sidebar comes but also some code error :

Warning: in_array() expects parameter 2 to be array, null given in /home/content/81/9560/html/ko/html/searchresults.php on line 76

Warning: in_array() expects parameter 2 to be array, null given in /home/content/81/9560/html/ko/html/searchresults.php on line 76

Warning: in_array() expects parameter 2 to be array, null given in /home/content/81/9560/html/kok/html/searchresults.php on line 140

Submitted by support on Fri, 2012-09-14 14:44

Hi there,

Ah - you'll need a merged version of search.php also - I'll send over now...

Cheers,
David.
--
PriceTapestry.com

Submitted by technoarenasol on Wed, 2012-11-14 12:19

technoarenasol

Hi David

How to change default list view to grid view ??

Link : {link saved}

Submitted by support on Wed, 2012-11-14 13:36

Hi,

Firstly in search.php look for this code around line 327:

      if ($view)
      {
        $viewText = "<a href='".$viewHREF."'>".translate("List View")."</a>";
      }
      else
      {
        $viewHREF .= "view=grid";
        $viewText = "<a href='".$viewHREF."'>".translate("Grid View")."</a>";
      }

...and REPLACE with:

      if ($view)
      {
        $viewText = "<a href='".$viewHREF."'>".translate("Grid View")."</a>";
      }
      else
      {
        $viewHREF .= "view=list";
        $viewText = "<a href='".$viewHREF."'>".translate("List View")."</a>";
      }

And then in html/searchresults.php look for this code around line 5:

  <?php if ($_GET["view"]=="grid"): ?>

...and REPLACE with;

  <?php if ($_GET["view"]<>"grid"): ?>

Cheers,
David.
--
PriceTapestry.com

Submitted by philstone on Thu, 2012-11-15 11:40

hi David

was wondering if there was the possibility of having a download mod that has the sidebar filter list option and also the grid/list view option? or would that be very complicated?

regards

Phil Stone
www.buy24-7.net

Submitted by support on Thu, 2012-11-15 12:21

Hi Phil,

No problem I'll make you a merged version and forward by email shortly...

Cheers,
David.
--
PriceTapestry.com

Submitted by shaunmac on Tue, 2012-12-04 17:37

How would I get this to function in wordpress?

Submitted by support on Wed, 2012-12-05 09:21

Hi Shaun,

It's a little more complex in the plugin as the conditional logic would need to be built into the template, possibly to include the switching code there. Please bear with me and I'll give it a go on my test server and let you know - I think enabling PHP sections within the template rather than making modifications everywhere to support switching may be the way forward...

Cheers,
David.
--
PriceTapestry.com

Submitted by denz on Fri, 2013-01-18 22:32

SearchResultsGridList.zip within the download section provides a zero byte zip file : )

Submitted by support on Sat, 2013-01-19 08:03

Hello denz, and welcome to the forum!

Sorry about that, the file is now in place (it got lost during the recent server move)!

Cheers,
David.
--
PriceTapestry.com

Submitted by Keeop on Tue, 2017-11-14 09:58

Hi David,

I'm looking at implementing a grid/list system. I can't find the code on the downloads page? It is still available?

Cheers.
Keeop

Submitted by support on Tue, 2017-11-14 13:23

Hello Keeop,

The download related to a legacy search results HTML module from several distribution ago however I have just recently been experimenting with a version for the Responsive HTML templates (Foundation library) using JavaScript sessionStorage to persist the user's preferred view throughout their session. This method requires only a single change to search.php to generate the links to switch between views (as I think it is tidiest to have them alongside the order by links) however they could go directly into the search results HTML module if preferred (and this would mean that the links would appear for Related Products also).

Here's what i've come up with, as complete replacement html/searchresults.php

<?php
  if (file_exists("html/user_searchresults_before.php")) require("html/user_searchresults_before.php");
?>
<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>
<?php
  if (file_exists("html/user_searchresults_after.php")) require("html/user_searchresults_after.php");
?>

With this in place, edit search.php and look for the following code at line 485:

      $banner["h3"] = translate("Order by").": ".$sortRelevance.$sortRating." | ".translate("Price").": ".$sortPriceAsc.", ".$sortPriceDesc;

...and REPLACE with:

      $banner["h3"] = translate("Order by").": ".$sortRelevance.$sortRating." | ".translate("Price").": ".$sortPriceAsc.", ".$sortPriceDesc;
      $banner["h3"] .= " | View as: <a onclick='JavaScript:pt_sr_setView(\"grid\");'>Grid</a>, <a onclick='JavaScript:pt_sr_setView(\"list\");'>List</a>";

That's basically it, however as above with regards to using grid view, this version uses Foundation's -block-grid-4 layout for grid view so $config_resultsPerPage (config.php line 20) should be set to a multiple of 4, and also the number of Related Products set to 4 (it is 3 by default). To do this, edit products.php and look for the following code at line 115:

    $sql = "SELECT DISTINCT(name),MATCH name AGAINST ('".database_safe($q)."') AS relevance FROM `".$config_databaseTablePrefix."products` ".($ignoreFullText?"IGNORE INDEX (name_2)":"USE INDEX (name_2)")." WHERE ".$where." ORDER BY relevance DESC LIMIT 3";

...and REPLACE with:

    $sql = "SELECT DISTINCT(name),MATCH name AGAINST ('".database_safe($q)."') AS relevance FROM `".$config_databaseTablePrefix."products` ".($ignoreFullText?"IGNORE INDEX (name_2)":"USE INDEX (name_2)")." WHERE ".$where." ORDER BY relevance DESC LIMIT 4";

Finally, in the new html/searchresults.php set your preferred default view in this line:

  if (typeof pt_sr_view == "undefined") pt_sr_view = "grid";

It also contains an inline text/css section - once all up and running and you have both views looking how you want this and any additional new CSS should be removed and incorporated into to html/default.css instead e.g.:

.pt_sr_center {
  text-align: center !important;
}

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by sirmanu on Wed, 2019-09-11 15:29

Hi! Is the above code still valid to have grid results?

Do you have any demo in the webpricecheck demo page?

Submitted by support on Thu, 2019-09-12 11:08

Yes,

All still valid - i've put it on the demo site for the query "mp3"...

http://www.webpricecheck.co.uk/search.php?q=mp3

Cheers,
David.
--
PriceTapestry.com

Submitted by sirmanu on Fri, 2019-09-13 08:34

Thank you very very much David!

Is it possible to display 2 items per row on mobile?

Submitted by support on Fri, 2019-09-13 08:59

Sure - for 2 columns on mobile in the <script> section, replace every instance of;

small-12

...with:

small-6

Cheers,
David.
--
PriceTapestry.com