Jump to content

Hiding subcategories from a "dropdown list"


Azraeliitti

Recommended Posts

We have a webshop with lots of products and some categories have several subcategories, subcategories of subcategories etc etc. When no category is chosen, it displays only the main categories and when you open a category, it will drop down *all* the subcategories. My intention is to only show subcategory level 2 ($s['cs_category_level'] == 2) when the site drop downs the subcategories which should reduce their amount notably. Sadly, my scripting skills aren't good enough to actually add anything new to the code rather than copypasting the portions of the old code, so could someone help out with it?:

//-----------------------------------------------------------------// Lets show the dynamic links of the product categories.//-----------------------------------------------------------------																  	$result = mysql_query ("SELECT * FROM $clover_shop_categories WHERE cs_category_title IS NOT NULL ORDER BY cs_category_listing_position asc");		if (mysql_num_rows ($result)) {  unset ($navecho_open, $nav_echo_closed, $nav_open_this_one);    echo "<TABLE cellpadding=2 cellspacing=0 border=0 width=\"100%\ height=\"100%\">\n\n";  while ($s = mysql_fetch_array ($result)) {	  if ($s['cs_category_level'] == 1) {	if ($nav_open_this_one && $nav_echo_open) {		echo $nav_echo_open;	} else {		echo $nav_echo_closed;	}	unset ($nav_echo_open, $nav_echo_closed, $nav_open_this_one);	  	  }	  $nav_echo_open .= "<TR><TD class=\"nav_open\"><P class=\"nav_open\">";	  	  if ($s['cs_category_level'] != 1) {		for ($i = 2; $i <= $s['cs_category_level']; $i++) {		if ($i == $s['cs_category_level']) {	  $nav_echo_open .= " <img src=\"logos/tree_corner.gif\" width=\"11\" height=\"11\" alt=\"\">";	  } else {	  $nav_echo_open .= " <img src=\"logos/tree_empty.gif\" width=\"11\" height=\"11\" alt=\"\">";		}	}		  }	  	  if ($c == $s[cs_category_id]) $nav_echo_open .= "<B>";	  $nav_echo_open .= "<a href=\"$config[cs_setting_cat_url]/product_catalog.php?c=$s[cs_category_id]\" class=\"nav_open\">$s[cs_category_title]</a>";	  if ($c == $s[cs_category_id]) $nav_echo_open .= "</B>";	  $nav_echo_open .= "</P></TD></TR>\n\n";	  if ($s['cs_category_level'] == 1) {		$nav_echo_closed .= "<TR><TD class=\"nav_closed\"><P class=\"nav_closed\">";	for ($i = 2; $i <= $s['cs_category_level']; $i++) {		if ($i == $s['cs_category_level']) {	  $nav_echo_closed .= " <img src=\"logos/tree_corner.gif\" width=\"11\" height=\"11\" alt=\"\">";	  } else {	  $nav_echo_closed .= " <img src=\"logos/tree_empty.gif\" width=\"11\" height=\"11\" alt=\"\">";		}	}	$nav_echo_closed .= "<a href=\"$config[cs_setting_cat_url]/product_catalog.php?c=$s[cs_category_id]\" class=\"nav_closed\">$s[cs_category_title]</a>";	$nav_echo_closed .= "</P></TD></TR>\n\n";  	  }  	  if ($c == $s['cs_category_id']) $nav_open_this_one = 1;	    }    if ($nav_open_this_one && $nav_echo_open) {	  echo $nav_echo_open;  } else {	  echo $nav_echo_closed;  }  echo "</TABLE>\n\n";	  unset ($nav_echo_open, $nav_echo_closed, $nav_open_this_one);		}

Link to comment
Share on other sites

When no category is chosen, it displays only the main categories and when you open a category, it will drop down *all* the subcategories.
Do you mean something like this: http://scott100.atspace.com/Drop_Menu.htmlSet submenu's to display:none then when the menu is clicked change to display:blockI'm sure you will be able to copy and paste it into your menu system to get what you need. 
Link to comment
Share on other sites

Nope, but that's almost better. If I could do that and get figured out how to prevent level 3 categories from showing up in the menu tree it would rule :) Edit: Unless you can make level 3 to show and hide as a submenu for level 2 too.

Link to comment
Share on other sites

Like i said before set the submenu (level 2,3 whatever) you don't wan't to see to display:none, then when the user click the top level display the submenu.It might not look exactly what you want but i think it functions like what you want.

Link to comment
Share on other sites

The solution in hiding categories was painfully simple after I really started figuring it out. All it needed was just a little addition to SQL query that sorted categories with bigger level than 2 out. I haven't really started implementing that script but from what I saw on that example page, I'm just wondering if that can work out when main categories are already linked to other pages?EDIT: Moreover, there is already method for opening the categories in the script and statements when they're closed. Can't pasting same methods twice in java over the script cause problems?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...