You are here:  » Display Products below Category Buttons


Display Products below Category Buttons

Submitted by ChrisNBC on Wed, 2019-07-31 11:35 in

Hi David,

Hope all is going well.

I wondered if you might be able to help me with a modification....The site I’m working on uses category hierarchy, the main nav menus contain second level category links. When a second level category is selected from the nav menu, link buttons are displayed so that a third level category can then be chosen. I would like to display second level products below the third level buttons and wondered if you might be able to suggest how I might be able to modify the code to do this.

An example page is:

{link saved}

Thanks in advance.

Best regards
Chris

Submitted by support on Wed, 2019-07-31 12:07

Hi Chris,

In categories.php, immediately after html/atoz.php has been included to display the sub-categories $category["id"] will be in context which could be used to select products to display using the Featured Products layout. To give this a go, look for the following code at line 103:

  if (isset($atoz)) require("html/atoz.php");

...and REPLACE with:

  if (isset($atoz)) require("html/atoz.php");
  if (isset($category["id"]))
  {
    $sql = "SELECT name,1 AS sequence FROM `".$config_databaseTablePrefix."products` WHERE categoryid='".$category["id"]."' LIMIT 3";
    if (database_querySelect($sql,$rows))
    {
      $sqlNames = array();
      $sqlCase = "CASE normalised_name";
      foreach($rows as $featured)
      {
        $featured["name"] = tapestry_normalise($featured["name"]);
        $sqlNames[] = "'".$featured["name"]."'";
        $sqlCase .= " WHEN '".database_safe($featured["name"])."' THEN ".$featured["sequence"];
      }
      $sqlCase .= " END AS sequence";
      $sqlIn = implode(",",$sqlNames);
      $sql = "SELECT * , MIN( price ) AS minPrice, MAX( price ) AS maxPrice, COUNT( id ) AS numMerchants, ".$sqlCase." FROM `".$config_databaseTablePrefix."products` WHERE normalised_name IN (".$sqlIn.") GROUP BY normalised_name ORDER BY sequence";
      database_querySelect($sql,$rows);
      $featured["products"] = $rows;
      foreach($featured["products"] as $k => $product)
      {
        $featured["products"][$k]["productHREF"] = tapestry_productHREF($product);
        $featured["products"][$k]["reviewHREF"] = tapestry_reviewHREF($product);
      }
    }
    if (isset($featured)) require("html/featured.php");
  }

Adjust "LIMIT 3" in the initial SELECT query as required for the number of results you wish to display...

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by ChrisNBC on Wed, 2019-07-31 21:31

Hi David,

Thanks as always fr your super quick reply. I have tried the code and it works perfectly but I wondered if there might be a way to show the category buttons on the standard search results page (which includes sidebar filters) instead of the 'featured' page format?

My standard results page looks like this:

{link saved}

Thanks in advance.

Best regards
Chris

Submitted by support on Thu, 2019-08-01 08:46

Hi Chris,

Depending on your template a staring point might simply be to call in searchresults.php instead of featured.php - so where you have the following code in the modification described above;

     if (isset($featured)) require("html/featured.php");

...REPLACE with:

     if (isset($featured))
     {
       $searchresults = $featured;
       require("html/searchresults.php");
     }

Cheers,
David.
--
PriceTapestry.com

Submitted by ChrisNBC on Thu, 2019-08-01 11:32

Hi David,

Thanks for the above. I tried the change to searchresults.php but nothing appears to change in whats displayed. I wondered if you might be able to suggest if there is anything else I could try to get this working.

Thanks in advance.

Best regards
Chris

Submitted by support on Thu, 2019-08-01 11:40

Sorry Chris, the the $featured variable needed to be copied into $searchresults for use by html/searchresults.php - replacement corrected above...

Cheers,
David.
--
PriceTapestry.com

Submitted by ChrisNBC on Thu, 2019-08-01 12:19

Hi David,

Thanks for the quick reply, I did wonder about the $featured. I have modified the code as you suggested but something is still going wrong somewhere as I get a page which looks a bit like the featured format with 3 products per row and then part way down the page the format changes and one product is displayed per row. Also, the sidebar filters and searchresults header are not displayed.

An example page is:

{link saved}

I wondered if you might be able to suggets what's going wrong and anything I could try to remedy it?

Thanks in advance.

Best regards
Chris

Submitted by support on Thu, 2019-08-01 12:22

Hi Chris,

Please could you email me your search.phphtml/searchresults.php and I'll make sure that the code above is populating everything required for the search results display layout...

Cheers,
David.
--
PriceTapestry.com

Submitted by ChrisNBC on Thu, 2019-08-01 13:10

Thanks David, I've just e-mailed both files.

Best regards
Chris

Submitted by ChrisNBC on Tue, 2019-08-27 21:42

Hi David,

The above mod is working beautifully. One thing I have noticed is that when a category has no products in it the button for that category is still displayed. I wondered if you might be able to suggest a way I can modify the button loop so that only buttons with products in that category are displayed.

Thanks in advance.

Best regards

Chris

Submitted by support on Wed, 2019-08-28 09:43

Hi Chris,

Are the buttons the only route to lower level categories where there may be products or do you have an alternative navigation?

Cheers,
David.
--
PriceTapestry.com

Submitted by ChrisNBC on Wed, 2019-08-28 21:29

Hi David,

Thanks as always for your quick reply. The navigation bar provides a route to level one and two categories but the buttons are the only route to level three categories.

Best regards

Chris

Submitted by support on Thu, 2019-08-29 10:41

Hi Chris,

Will follow up by email with a mod to the categories.php sent previously...

Cheers,
David.
--
PriceTapestry.com