You are here:  » Main categories in sidebox


Main categories in sidebox

Submitted by wesse249 on Mon, 2016-08-15 07:42 in

Hello David,

I have created a sidebox in the older version of your script. Can you tell me how i can add only the main categories vertical in it? Like this (also with stripe or bullit):

- Bedden
- Bedtextiel
- Bergkasten
- Bijzettafels
- Boekenkasten
- Boxsprings
- Buffetkasten
- Bureaus

Thank you Jan Roel

Submitted by support on Mon, 2016-08-15 11:16

Hello Jan,

If your old version is using this SQL:

  $sql = "SELECT DISTINCT(category) FROM `".$config_databaseTablePrefix."products` WHERE category <> '' ORDER BY category";

Then with 15/09A / Category Hierarchy, to get the top level categories you can just replace that with:

  $sql = "SELECT name AS category FROM `".$config_databaseTablePrefix."categories_hierarchy` WHERE parent='0' ORDER BY category";

If your initial select is not quite the same as above or you're not sure how to modify the example for 15/09A to suit your code let me know what you're currently using and I'll show you how to modify as required...

Cheers,
David.
--
PriceTapestry.com

Submitted by wesse249 on Wed, 2016-08-17 06:49

Hello David,

Thanks. And when i place the code in the sidebox it shows up like this:

- Bedden
- Bedtextiel
- Bergkasten
- Bijzettafels
- Boekenkasten
- Boxsprings
- Buffetkasten
- Bureaus

Thanks Jan Roel

Submitted by support on Wed, 2016-08-17 08:43

Hello Jan,

Here's the complete code for a list of top level categories;

  $sql = "SELECT name AS category FROM `".$config_databaseTablePrefix."categories_hierarchy` WHERE parent='0' ORDER BY category";
  database_querySelect($sql,$rows);
  print "<ul>";
  foreach($rows as $row)
  {
    print "<li><a href='".tapestry_indexHREF("category",$row["category"])."'>".$row["category"]."</a></li>";
  }
  print "</ul>";

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by wesse249 on Thu, 2016-08-18 09:31

Hello David,

Thank you very much! Happy with it. Do you maybe know the trick (when the menu has for example more then 20 categories) how to collapse the menu?

Submitted by support on Thu, 2016-08-18 11:17

Hello Jan,

This is the technique used to reveal the search filters in mobile view - the general idea being; put the content to be revealed inside a <div> with the display style set to "none". In a separate element the "Show more..." text has a JavaScript onclick handler that then hides itself and reveals the currently hidden <div> by setting the display style back to "block"...

  $sql = "SELECT name AS category FROM `".$config_databaseTablePrefix."categories_hierarchy`
            WHERE parent='0' ORDER BY category";
  database_querySelect($sql,$rows);
  $max = 20;
  print "<ul>";
  foreach($rows as $k => $row)
  {
    print "<li><a href='".tapestry_indexHREF("category",$row["category"])."'>".$row["category"]."</a></li>";
    if ($k==($max-1))
    {
      print "<li id='more1show'
        onclick='JavaScript:this.style.display=\"none\";
        document.getElementById(\"more1\").style.display=\"block\"'>Show more...</li>";
      print "<div id='more1' style='display:none;'>";
    }
  }
  print "</div>";
  print "</ul>";

Cheers,
David.
--
PriceTapestry.com

Submitted by wesse249 on Sun, 2016-08-21 17:50

Hello David,

Thank you very much! Only one problem the categories aren't showing up. Is the problem maybe because of this topic? I use multiple installation.

I placed the code like this in my website (html/banner.php):

{code saved}

<?php
$merchant 
trim(file_get_contents("merchant.txt"));
$sql "SELECT DISTINCT(name) AS category FROM `".$config_databaseTablePrefix."categories_hierarchy` WHERE merchant='".database_safe($merchant)."' ORDER BY category";
?>

Thanks Jan Roel

Submitted by support on Mon, 2016-08-22 08:50

Hello Jan,

There's no `merchant` field on the categories_hierarchy table but you could do it with a sub-query on the products table; have a go with:

<?php
$merchant 
trim(file_get_contents("merchant.txt"));
$sql "SELECT DISTINCT(name) AS category FROM `".$config_databaseTablePrefix."categories_hierarchy` WHERE id IN ( SELECT DISTINCT(categoryid) FROM `".$config_databaseTablePrefix."products` WHERE merchant='".database_safe($merchant)."') AND parent='0' ORDER BY category";
?>

Cheers,
David.
--
PriceTapestry.com

Submitted by wesse249 on Mon, 2016-08-22 12:01

Hello David,

When i add this code into html/banner.php

{code saved}

Then i get this error:

{code saved}

Thanks Jan Roel

Submitted by support on Mon, 2016-08-22 13:03

Hello Jan,

My apologies, it's actually `categoryid` not `category_id` on the products table. Corrected above, however it occurred to me that an additional step is required, as the sub-query is not necessarily returning top level categories. The following should do the trick, which scans each top level category for at least one sub-category containing products from the merchant selected from your merchant.txt file...

<?php
  $merchant 
trim(file_get_contents("merchant.txt"));
  
$sql "SELECT id,name AS category FROM `".$config_databaseTablePrefix."categories_hierarchy`
            WHERE parent='0' ORDER BY category"
;
  
database_querySelect($sql,$rows);
  foreach(
$rows as $k => $row)
  {
    
$rows[$k]["lowerarchy"] = tapestry_categoryHierarchyLowerarchy($id);
  }
  
$sql2 "SELECT DISTINCT(categoryid) FROM `".$config_databaseTablePrefix."products` WHERE merchant='".database_safe($merchant)."'";
  
database_querySelect($sql2,$rows2);
  foreach(
$rows as $k => $row)
  {
    
$found FALSE;
    foreach(
$rows2 as $row2)
    {
      if (
in_array($row2["categoryid"],$rows[$k]["lowerarchy"]))
      {
        
$found TRUE;
        break;
      }
    }
    if (!
$found) unset($rows[$k]);
  }
  
$max 20;
  print 
"<ul>";
  foreach(
$rows as $k => $row)
  {
    print 
"<li><a href='".tapestry_indexHREF("category",$row["category"])."'>".$row["category"]."</a></li>";
    if (
$k==($max-1))
    {
      print 
"<li id='more1show'
        onclick='JavaScript:this.style.display=\"none\";
        document.getElementById(\"more1\").style.display=\"block\"'>Show more...</li>"
;
      print 
"<div id='more1' style='display:none;'>";
    }
  }
  print 
"</div>";
  print 
"</ul>";
?>

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by wesse249 on Tue, 2016-08-23 09:30

Hello David,

The strange thing is nothing showes up when adding the code in html/banner.php. The product section is moving completly to the left. See here: {link saved}

Do you now how this is possible? I use this node for creating sidebar: http://www.pricetapestry.com/node/5821

Jan Roel

Submitted by support on Tue, 2016-08-23 09:42

Hello Jan,

Please could you email me modified html/banner.php and i'll check it out further with you...

Thanks,
David.
--
PriceTapestry.com

Submitted by wesse249 on Tue, 2016-08-23 19:45

Hello david,

How can i add also a sidebox to the homepage? I use html/featured.php.

{code saved}

Thanks Jan Roel

Submitted by support on Wed, 2016-08-24 09:49

Hello Jan,

To put a sidebar alongside (or above for mobile view) Featured Products on the home page, edit index.php and look for the following code at line 47:

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

...and REPLACE with:

?>
<div class='row'>
<div class='small-12 medium-2 columns'>
  <!-- sidebar content here -->
</div>
<div class='small-12 medium-10 columns'>
<?php
  if (isset($featured)) require("html/featured.php");
?>
</div>
</div>
<?php

Cheers,
David.
--
PriceTapestry.com

Submitted by wesse249 on Wed, 2016-08-24 19:52

Thank you very much David,

I feel myself very stupid. Normally i can create some css stuff but now i can't fix it.

I want the font size of the category has the same size as the product title. But everything i do nothing works.

Thanks Jan roel

Submitted by support on Thu, 2016-08-25 08:30

Hello Jan,

Featured Products name font size is inheriting the body font size (12px) but it looks like Foundation is styling <ul><li>... differently, so what you can do is give a class to the list and then set the font size as required.

In the category sidebar code from above, where you have the opening <ul> being output by this line:

  print "<ul>";

...REPLACE with:

  print "<ul class='pt_sidebar_cat'>";

And then to html/default.css add the following:

.pt_sidebar_cat li a {
  font-size: 12px !important;
}

Hope this helps!

Cheers,
David.
--
PriceTapestry.com