You are here:  » Show only category with products in it


Show only category with products in it

Submitted by wesse249 on Thu, 2017-02-02 21:10 in

Hello David,

I have a lot of categories in the category hierarchy. Some categories don't have products yet. Is it posible not showing the categories without products?

In the footer of my pages i show the following text: Category name you find at {link saved}
Only now all the categries are show like this: {code saved}
Is it possible to only show the last category?

Thanks Jan Roel

Submitted by support on Fri, 2017-02-03 10:56

Hello Jan,

You could remove lowest level sub-categories that do not yet have any products from the menu easily - to do this, edit html/categories_menu.php and look for the following code at line 30:

        $categoryHierarchyArray = tapestry_categoryHierarchyArray(array($category["id"]));

...and REPLACE with:

$sql = "SELECT id FROM `".$config_databaseTablePrefix."products` WHERE categoryid='".$category["id"]."' LIMIT 1";";
        if (!database_querySelect($sql,$r)) continue;
        $categoryHierarchyArray = tapestry_categoryHierarchyArray(array($category["id"]));

Regarding the $q display at the bottom of the page, I assume that you are generating this with something like:

<p><?php print $q?> at example.com</p>

To tidy this up to remove the search operator for merchant / category / brand searches, and in the case of category, show last category only, have a go with something like;

<?php
  $footer_q = str_replace(array("merchant:","category:","brand:"),"",$q);
  if ($parts[0]=="category")
  {
    $p = explode("/",$footer_q);
    $footer_q = array_pop($p);
  }
?>
<p><?php print $footer_q?> at example.com</p>

Hope this helps!

Cheers,
David.
--
PriceTapestry.com