Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Hiding sub categories


unistar

Recommended Posts

I would like to hide the subcategories (from showing) on the categories box but maintain the sub categories showing on the main page. I've tried commenting out editing some code but it not working. Anybody done it or know?

 

function tep_show_category($counter) {

global $foo, $categories_string, $id;

for ($a=0; $a<$foo[$counter]['level']; $a++) {

$categories_string .= " "; }

 

$categories_string .= '<img src="http://www.server.com/catalog/images/arro_btn.gif"><a href="';

if ($foo[$counter]['parent'] == 0) {

$cPath_new = 'cPath=' . $counter;

} else {

$cPath_new = 'cPath=' . $foo[$counter]['path']; }

 

$categories_string .= tep_href_link(FILENAME_DEFAULT, $cPath_new);

$categories_string .= '">';

if ( ($id) && (in_array($counter, $id)) ) {

$categories_string .= '<font color=red><strong><u>'; }

 

// display category name

$categories_string .= $foo[$counter]['name'];

if ( ($id) && (in_array($counter, $id)) ) {

$categories_string .= '</strong></u></font>'; }

 

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 .= '<br>';

if ($foo[$counter]['next_id']) {

tep_show_category($foo[$counter]['next_id']); } } ?>

Link to comment
Share on other sites

  • 4 weeks later...
  • 4 weeks later...

In 2.2 this is the code that you need to comment out in categories.php found in catalog/includes/boxes

 

You probably already know but the /* at the beginning and the */ at the end will comment out the whole section.

 

/*if ($cPath) {

$new_path = '';

$id = split('_', $cPath);

reset($id);

while (list($key, $value) = each($id)) {

unset($prev_id);

unset($first_id);

$categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.parent_id = '" . $value . "' and c.categories_id = cd.categories_id and cd.language_id='" . $languages_id ."' order by sort_order, cd.categories_name");

$category_check = tep_db_num_rows($categories_query);

if ($category_check > 0) {

$new_path .= $value;

while ($row = tep_db_fetch_array($categories_query)) {

$foo[$row['categories_id']] = array(

'name' => $row['categories_name'],

'parent' => $row['parent_id'],

'level' => $key+1,

'path' => $new_path . '_' . $row['categories_id'],

'next_id' => false

);

 

if (isset($prev_id)) {

$foo[$prev_id]['next_id'] = $row['categories_id'];

}

 

$prev_id = $row['categories_id'];

 

if (!isset($first_id)) {

$first_id = $row['categories_id'];

}

 

$last_id = $row['categories_id'];

}

$foo[$last_id]['next_id'] = $foo[$value]['next_id'];

$foo[$value]['next_id'] = $first_id;

$new_path .= '_';

} else {

break;

}

}

}

*/

 

Check out www.expertcellular.com to see how it works!

Link to comment
Share on other sites

  • 1 month later...
  • 2 weeks later...

Does anyone know of any mods or contributions that will display in the categories infobox, only the main categories in list box format. I have tried using several contributions, but it includes the categories as well as the sub categories within the list box.

 

In addition to this, is it possible to have another infobox open displaying the sub-categories when one of the top level categories is clicked in the categories infobox.

 

I have made attempts by taking this info from the default.php page, and creating an infobox with this code, but it turns out looking pretty screwy.

 

if ($cPath && ereg('_', $cPath)) {

// check to see if there are deeper categories within the current category

$category_links = array_reverse($cPath_array);

$size = sizeof($category_links);

for($i=0; $i<$size; $i++) {

$categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.categories_image, c.parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.parent_id = '" . $category_links[$i] . "' and c.categories_id = cd.categories_id and cd.language_id = '" . $languages_id . "' order by sort_order, cd.categories_name");

if (tep_db_num_rows($categories_query) < 1) {

// do nothing, go through the loop

} else {

break; // we've found the deepest category the customer is in

}

}

} else {

$categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.categories_image, c.parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.parent_id = '" . $current_category_id . "' and c.categories_id = cd.categories_id and cd.language_id = '" . $languages_id . "' order by sort_order, cd.categories_name");

}

 

$rows = 0;

while ($categories = tep_db_fetch_array($categories_query)) {

$rows++;

$cPath_new = tep_get_path($categories['categories_id']);

$width = (int)(100 / MAX_DISPLAY_CATEGORIES_PER_ROW) . '%';

// echo ' <td align="center" class="smallText" style="width: ' . $width . '" valign="top"><a href="' . tep_href_link(FILENAME_DEFAULT, $cPath_new, 'NONSSL') . '">' . tep_image(DIR_WS_IMAGES . $categories['categories_image'], $categories['categories_name'], SUBCATEGORY_IMAGE_WIDTH, SUBCATEGORY_IMAGE_HEIGHT) . '<br>' . $categories['categories_name'] . '</a></td>' . "n";

echo ' <td align="center" class="smallText" style="width: ' . $width . '" valign="top"><a href="' . tep_href_link(FILENAME_DEFAULT, $cPath_new, 'NONSSL') . '">' . '<br>' . $categories['categories_name'] . '</a></td>' . "n";

if ((($rows / MAX_DISPLAY_CATEGORIES_PER_ROW) == floor($rows / MAX_DISPLAY_CATEGORIES_PER_ROW)) && ($rows != tep_db_num_rows($categories_query))) {

echo ' </tr>' . "n";

echo ' <tr>' . "n";

}

}

?>

 

I am fairly new to scripting and oscommerce, but have never come across such a great customizeable ecommerce solution.

Link to comment
Share on other sites

  • 4 years later...

Hellom i can't use the workaround from "unistar".

This ist my categories.php code

 

<?php
/*
 $Id: categories.php,v 1.25 2003/07/09 01:13:58 hpdl Exp $

 osCommerce, Open Source E-Commerce Solutions
 http://www.oscommerce.com

 Copyright (c) 2003 osCommerce

 Released under the GNU General Public License

 changed August 2003, by Nils Petersson
 contribution "Category Box Enhancement", version 1.1
*/

 function tep_show_category($counter) {

// BoF - Contribution Category Box Enhancement 1.1
global $tree, $categories_string, $cPath_array, $cat_name;

for ($i=0; $i<$tree[$counter]['level']; $i++) {
  $categories_string .= "  ";
}
$cPath_new = 'cPath=' . $tree[$counter]['path'];
if (isset($cPath_array) && in_array($counter, $cPath_array) && $cat_name == $tree[$counter]['name']) { //Link nicht anklickbar, wenn angewählt
		 $categories_string .= '<a href="';
		 $categories_string .= tep_href_link(FILENAME_DEFAULT, $cPath_new) . '">'; //Link nicht anklickbar, wenn angewählt
} else {//Link nicht anklickbar, wenn angewählt
$categories_string .= '<a href="';
$categories_string .= tep_href_link(FILENAME_DEFAULT, $cPath_new) . '">';
}//Link nicht anklickbar, wenn angewählt
if (tep_has_category_subcategories($counter)) {
  $categories_string .= tep_image(DIR_WS_IMAGES . 'pointer_blue.gif', '');
}
else {
  $categories_string .= tep_image(DIR_WS_IMAGES . 'pointer_blue_light.gif', '');
}

if (isset($cPath_array) && in_array($counter, $cPath_array)) {
  $categories_string .= '<b>';
}

if ($cat_name == $tree[$counter]['name']) {
  $categories_string .= '<span class="errorText">';
}

// display category name
$categories_string .= $tree[$counter]['name'];

	if ($cat_name == $tree[$counter]['name']) {
		$categories_string .= '</span>';
}

if (isset($cPath_array) && in_array($counter, $cPath_array)) {
  $categories_string .= '</b>';
}
// 	EoF Category Box Enhancement

$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 .= '<br>';

if ($tree[$counter]['next_id'] != false) {
  tep_show_category($tree[$counter]['next_id']);
}
 }
?>
<!-- categories //-->
	  <tr>
		<td><?php

// BoF - Contribution Category Box Enhancement 1.1
if (isset($cPath_array)) {
	for ($i=0, $n=sizeof($cPath_array); $i<$n; $i++) {
			$categories_query = tep_db_query("select categories_name from " . TABLE_CATEGORIES_DESCRIPTION . " where categories_id = '" . (int)$cPath_array[$i] . "' and language_id = '" . (int)$languages_id . "'");
			if (tep_db_num_rows($categories_query) > 0)
			$categories = tep_db_fetch_array($categories_query);
	}
$cat_name = $categories['categories_name'];
}
// EoF Category Box Enhancement
// display category name

 $info_box_contents = array();
 $categories_string = '';
 $tree = array();

 $categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.parent_id = '0' and c.categories_id = cd.categories_id and c.categories_status = '1' and cd.language_id='" . (int)$languages_id ."' order by sort_order, cd.categories_name");
 while ($categories = tep_db_fetch_array($categories_query))  {
$tree[$categories['categories_id']] = array('name' => $categories['categories_name'],
											'parent' => $categories['parent_id'],
											'level' => 0,
											'path' => $categories['categories_id'],
											'next_id' => false);

if (isset($parent_id)) {
  $tree[$parent_id]['next_id'] = $categories['categories_id'];
}

$parent_id = $categories['categories_id'];

if (!isset($first_element)) {
  $first_element = $categories['categories_id'];
}
 }

 //------------------------
 if (tep_not_null($cPath)) {
$new_path = '';
reset($cPath_array);
while (list($key, $value) = each($cPath_array)) {
  unset($parent_id);
  unset($first_id);
  $categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.parent_id = '" . (int)$value . "' and c.categories_id = cd.categories_id and c.categories_status = '1' and cd.language_id='" . (int)$languages_id ."' order by sort_order, cd.categories_name");
  if (tep_db_num_rows($categories_query)) {
	$new_path .= $value;
	while ($row = tep_db_fetch_array($categories_query)) {
	  $tree[$row['categories_id']] = array('name' => $row['categories_name'],
										   'parent' => $row['parent_id'],
										   'level' => $key+1,
										   'path' => $new_path . '_' . $row['categories_id'],
										   'next_id' => false);

	  if (isset($parent_id)) {
		$tree[$parent_id]['next_id'] = $row['categories_id'];
	  }

	  $parent_id = $row['categories_id'];

	  if (!isset($first_id)) {
		$first_id = $row['categories_id'];
	  }

	 $last_id = $row['categories_id'];
	}
	$tree[$last_id]['next_id'] = $tree[$value]['next_id'];
	$tree[$value]['next_id'] = $first_id;
	$new_path .= '_';
  } else {
	break;
  }
}
 }
 tep_show_category($first_element);

 $info_box_contents = array();
 $info_box_contents[] = array('text' => $categories_string);

// if ( (basename($PHP_SELF) != FILENAME_SPECIALS)) {
// $info_box_contents[] = array('align' => 'center',
//							   'text'  => '<font size=-2><b><a href="' . tep_href_link(FILENAME_SPECIALS, '', 'NONSSL') . '">' . BOX_INFORMATION_SPECIALS . '</a></b></font>');
// }else{
// $info_box_contents[] = array('align' => 'center',
//							   'text'  => '<font size=-2><b><a href="' . tep_href_link(FILENAME_SPECIALS, '', 'NONSSL') . '"><span class="errorText">' . BOX_INFORMATION_SPECIALS . '</a></b></font></span>');
//  }
 function tep_get_paths($categories_array = '', $parent_id = '0', $indent = '', $path='') {
global $languages_id;

if (!is_array($categories_array)) $categories_array = array();

$categories_query = tep_db_query("select c.categories_id, cd.categories_name from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where parent_id = '" . (int)$parent_id . "' and c.categories_id = cd.categories_id and c.categories_status = '1' and cd.language_id = '" . (int)$languages_id . "' order by sort_order, cd.categories_name");
while ($categories = tep_db_fetch_array($categories_query)) {
  if ($parent_id=='0'){
$categories_array[] = array('id' => $categories['categories_id'],
								  'text' => $indent . $categories['categories_name']);
  }
  else{
$categories_array[] = array('id' => $path . $parent_id . '_' .$categories['categories_id'],
								  'text' => $indent . $categories['categories_name']);
  }

  if ($categories['categories_id'] != $parent_id) {
$this_path=$path;
if ($parent_id != '0')
  $this_path = $path . $parent_id . '_';
	$categories_array = tep_get_paths($categories_array, $categories['categories_id'], $indent . ' ', $this_path);
  }
}

return $categories_array;
 }

 new infoBox($info_box_contents);
?></td>
	  </tr>
<!-- categories_eof //-->

 

Does anyone know which code needed to comment out to disable the subcategories view?

Link to comment
Share on other sites

  • 2 months later...

Hello,

 

I use RC1 and I commented the following code in order to display top categories only - no subcategories - .

 

comment the code in this file

 

includes/boxes/categories.php

 

I had to play a little bit with the css afterward to make sure that the layout did not get messed up.

 

hope it helps

 

...

 

//------------------------

/*if ($cPath) {

$cPath_array = split('_', $cPath);

reset($cPath_array);

while (list($key, $value) = each($cPath_array)) {

$new_path .= $value;

unset($parent_id);

unset($first_id);

$categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.parent_id = '" . $value . "' and c.categories_id = cd.categories_id and cd.language_id='" . $languages_id ."' order by sort_order, cd.categories_name");

$category_check = tep_db_num_rows($categories_query);

while ($row = tep_db_fetch_array($categories_query)) {

$tree[$row['categories_id']] = array(

'name' => $row['categories_name'],

'parent' => $row['parent_id'],

'level' => $key+1,

'path' => $new_path . '_' . $row['categories_id'],

'next_id' => false

);

 

if (isset($parent_id)) {

$tree[$parent_id]['next_id'] = $row['categories_id'];

}

 

$parent_id = $row['categories_id'];

 

if (!isset($first_id)) {

$first_id = $row['categories_id'];

}

 

$last_id = $row['categories_id'];

}

if ($category_check != 0) {

$tree[$last_id]['next_id'] = $tree[$value]['next_id'];

$tree[$value]['next_id'] = $first_id;

}

 

$new_path .= '_';

}

}*/

 

...

Link to comment
Share on other sites

  • 3 weeks later...

I installed a template that apparently doesn't reference the categories.php box code. The header.php file has the categories code in it. My code was SLIGHTLY different than what was mentioned above, and I had to comment out a few extra lines at the top, but I got it to work. I don't know if that helps anyone but I thought I'd mention it.

Link to comment
Share on other sites

  • 3 months later...
In 2.2 this is the code that you need to comment out in categories.php found in catalog/includes/boxes

You probably already know but the /* at the beginning and the */ at the end will comment out the whole section.

/*if ($cPath) {

$new_path = '';

$id = split('_', $cPath);

reset($id);

while (list($key, $value) = each($id)) {

unset($prev_id);

unset($first_id);

$categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.parent_id = '" . $value . "' and c.categories_id = cd.categories_id and cd.language_id='" . $languages_id ."' order by sort_order, cd.categories_name");

$category_check = tep_db_num_rows($categories_query);

if ($category_check > 0) {

$new_path .= $value;

while ($row = tep_db_fetch_array($categories_query)) {

$foo[$row['categories_id']] = array(

'name' => $row['categories_name'],

'parent' => $row['parent_id'],

'level' => $key+1,

'path' => $new_path . '_' . $row['categories_id'],

'next_id' => false

);

if (isset($prev_id)) {

$foo[$prev_id]['next_id'] = $row['categories_id'];

}

$prev_id = $row['categories_id'];

if (!isset($first_id)) {

$first_id = $row['categories_id'];

}

$last_id = $row['categories_id'];

}

$foo[$last_id]['next_id'] = $foo[$value]['next_id'];

$foo[$value]['next_id'] = $first_id;

$new_path .= '_';

} else {

break;

}

}

}

*/

Check out www.expertcellular.com to see how it works!

 

Hi, but what happens when you hwant to disuplay just one subcategories if you have 3 or more subcategories.

Link to comment
Share on other sites

  • 1 month later...

Aha! This works! So awesome as I have more then 8,000 products. Thank you Abuelo 12!!!

 

  //------------------------
 if (tep_not_null($cPath)) {
$new_path = '';
reset($cPath_array);
while (list($key, $value) = each($cPath_array)) {
  unset($parent_id);
  unset($first_id);
  $categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.parent_id = '" . (int)$value . "' and c.categories_id = cd.categories_id and cd.language_id='" . (int)$languages_id ."' order by sort_order, cd.categories_name");
  if (tep_db_num_rows($categories_query)) {
	$new_path .= $value;
	while ($row = tep_db_fetch_array($categories_query)) {
	  $tree[$row['categories_id']] = array('name' => $row['categories_name'],
										   'parent' => $row['parent_id'],
										   'level' => $key+1,
										   'path' => $new_path . '_' . $row['categories_id'],
										   'next_id' => false);

	  if (isset($parent_id)) {
		$tree[$parent_id]['next_id'] = $row['categories_id'];
	  }

	  $parent_id = $row['categories_id'];

	  if (!isset($first_id)) {
		$first_id = $row['categories_id'];
	  }

	  $last_id = $row['categories_id'];
	}
	$tree[$last_id]['next_id'] = $tree[$value]['next_id'];
	$tree[$value]['next_id'] = $first_id;
	$new_path .= '_';
  } else {
	break;
  }
}
 }

 

Is what I had in my OSC, commented it out and it works awesome.

 

I had over 18 sub-categories within most main categories, and as you can imagine....my menu's were dropping very far even messing up my template. Not to mention making it very hard to find main categories!

Link to comment
Share on other sites

  • 1 month later...

hi,

i have a problem which i am not getting a reply to.... can anyone help me ......

 

in the url : http://mid-nignttemptation.com/final5/

 

when i click on any of the cateories in left hand side in the side box, the products are shown in the large image which distorts the alignment

it shows like this :

 

http://mid-nignttemptation.com/final5/index.php?cPath=26

 

can anyone plzz help me with this....

Link to comment
Share on other sites

Hi Burt,

Thanks a lot for responding, but i couldnt get much of a help from that...

The link doesnt have any download option and the link attached to it http://www.clubosc.com/horrible-or-awesome...ail-images.html went off my head

 

is there a simple way of getting this thing done....

 

like changing the code of a file????????????

 

if you know when we click on any category which are the files that are hit to show the respective products on the right hand side...... its definitely not product_info.php

 

Please guide me little further i would be greatful .....

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...