thall89553 Posted March 19, 2006 Posted March 19, 2006 Please look at this page Page Example You see the product categories down the left side? Some are followed by the number of current products in that category, those that are not followed by a number do not have products. It seems pointless to me to have links to categories that do not have products and I am trying to tweak the function that outputs the code. Here is that function: function tep_show_category($counter) { global $tree, $categories_string, $cPath_array; if ($tree[$counter]['parent'] == 0 ) { $categories_string .= '<li><a href="'; } else { $categories_string .= '<li class="sub_cat"><a href="'; } if ($tree[$counter]['parent'] == 0) { $cPath_new = 'cPath=' . $counter; } else { $cPath_new = 'cPath=' . $tree[$counter]['path']; } $categories_string .= tep_href_link(FILENAME_DEFAULT, $cPath_new) . '">'; if (isset($cPath_array) && in_array($counter, $cPath_array)) { $categories_string .= '<span class="current">'; } // display category name $categories_string .= $tree[$counter]['name']; if (isset($cPath_array) && in_array($counter, $cPath_array)) { $categories_string .= '</span>'; } if (tep_has_category_subcategories($counter)) { $categories_string .= '->'; } $categories_string .= '</a>'; if (SHOW_COUNTS == 'true') { $products_in_category = tep_count_products_in_category($counter); if ($products_in_category > 0) { $categories_string .= ' (' . $products_in_category . ')'; } } $categories_string .= '</li>'."\r"; if ($tree[$counter]['next_id'] != false) { tep_show_category($tree[$counter]['next_id']); } } It seems the solution lies here - if ($products_in_category > 0) as that is what determines if the product count is output. I thought I could take a variation of that statement and put it at the very top of the function, such as this if ($products_in_category !== 0) and it would prevent the output of a category all together if it had no products. Interestingly enough it works "sort of". I am not a php expert but I tried varitions of that conditional statement and can't quite nail it. Can somone help by chance? Tom
Guest Posted March 19, 2006 Posted March 19, 2006 if ($products_in_category !== 0) one too many = in here; try if ($products_in_category != 0) and dont forget to then enclose the rest of the query in { and }
thall89553 Posted March 19, 2006 Author Posted March 19, 2006 Thanks, I actually tried that as well. When I use the following: <?php function tep_show_category($counter) { global $tree, $categories_string, $cPath_array; $products_in_category = tep_count_products_in_category($counter);if($products_in_category != 0){....} I end up only getting 4 cateories when I know there are about 20 with products. Very strange. Tom
Guest Posted March 20, 2006 Posted March 20, 2006 The if statement needs to come further down the page, basically as soon as the script hits a category with 0 products, it stops looping; you need it to carry on looping, just skip that category, until its gone throuygh them all.
Recommended Posts
Archived
This topic is now archived and is closed to further replies.