Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

remove subcategories


Guest

Recommended Posts

Posted

on the left panel, where the categories are - how can i disable showing the nested categories - and only show the nested category if it's being viewed?

 

for instance, this is what it looks like now:

 

category1

category2

category3

- nested category1

- nested category2

- nested category3 (currently viewing a product in this category)

category4

category5

 

 

this is what i want it to look like:

category1

category2

category3

- nested category3 (currently viewing a product in this category)

category4

category5

Posted

so I've seen the other post about it but was thinking if you hide categories of the same level you reduce the navigation capabilities of the categories box. Because if you do this on the root categories only the selected one will show.

Posted

yeah i thought about that, it doesn't matter, cause i only have 1 layer of nested categories.

 

for instance:

1 tshirt category

subcategory is just the band name

 

that's as far as the subcategories go.

 

i found a fix after searching for the 10th time :)

http://www.oscommerce.com/forums/index.php?sho...66entry710566

 

now, would you happen to know how i can list ONLY the current subcategory beneath the bold (current / selected) category?

 

like this:

category1

category2

category3

- nested category3 (currently viewing a product in this category)

category4

category5

Posted

you could filter using the $current_category_id. Getting the sub-categories under it is not complicated. You could copy the tep_get_categories (if not already on the catalog side) from the admin side in general.php. Or the tep_get_subcategories could also do. But I don't know about the parent categories.

Posted

the parent categories are working the way i want them to, so they are no problem.

 

but i'm not quite sure what i need to get the subcategories under them... as everything you just posted is over my head :)

Posted
the parent categories are working the way i want them to, so they are no problem.

 

Yes they are working as the code is. But has to be modified and you basically want to drop the siblings of the selected category in the category tree. And so the categories path to the root should include all parent categories. Now you want to do this because you have way too many categories? I mean perhaps if you deploy a categories menu contrib or something would be easier.

Posted

yes i have 60+ subcategories at the moment and i still have hundreds of items that are being added everyday.

 

i would prefer to not list all subcategories at once - isn't that what most of the contributions do? when you click on a parent category - to the right body of the page it lists ALL subcategories as it is, that's fine. but on the left panel navigation i do not want that to occur, as it leaves a huge amount of blank space on my item pages, and i feel that having all the different keywords on a page will hurt me when it comes time for google to recalculate my PR.

 

and i would like to stay away from any JS contributions, most of my visitors seem to have it disabled according to my logs

Posted

How about if you have on your left navigation only the top categories since the others can be accessed once the client is in a sub-category. (plus you have the breadcrumb) Is that good enough?

 

edit: I use js for my navigation but I also set it up when js is disabled with a very similar layout. You can see my nav panel.

Posted

not sure what you mean really? i think i already have that.

i would like to display only the current subcategory in there too though

Posted

well you could try this as a test, it will only show the top categories, see if its practical enough. But to eliminate the siblings only, I don't have an easy solution.

 

includes\boxes\categories.php

 

find this

if (tep_not_null($cPath)) {

 

replace with this

$tmpPath = false;
 if (tep_not_null($tmpPath)) {

 

At least the selected top category remains highlighted when you browse sub-categories.

Posted

that was for the code I posted ok so try this

 

$tmpPath = false;

if (!$tmpPath)) {

 

replace the line

 

if (tep_not_null($cPath)) {

 

the other post was I think in the routine you should have the above line of code or better post the code you have.

Posted

correct me if i'm wrong:

 

 

find

if (tep_not_null($cPath)) {

 

 

replace with

$tmpPath = false;

if (!$tmpPath)) {

 

 

if this is right, i get a parse error on line 100.

 

line 100: if (!$tmpPath)) {

Posted

if (!$tmpPath) {

 

had an extra bracket there sorry, try it again

Posted

that didn't work :(

 

i moved some categories around, now the subcategories are back showing again. (my categories go 3 deep) - category1, subcategory1, sub-subcategory1

how can i remove them?

Posted

Ok I am not sure if there are mods with the code you have. Basically this is the code I was trying to disable to eliminate the sub-categories in the box file.

 

  //------------------------
 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;
  }
}
 }

 

You could take it out and see how it looks. Also you can post the categories code you have.

Posted

thank you, that worked :D

 

here is my categories:

<?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
*/

 function tep_show_category($counter) {
global $tree, $categories_string, $cPath_array;
if ($tree[$counter]['level'] == 1) {
   if ($tree[$counter]['next_id'] != false) {
	 tep_show_category($tree[$counter]['next_id']);
   }
 return;
  }

for ($i=0; $i<$tree[$counter]['level']; $i++) {
  $categories_string .= "  ";
}

$categories_string .= '<span class="cats"><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 .= '<b>';
}

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

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

if (tep_has_category_subcategories($counter)) {
  $categories_string .= '';
}

$categories_string .= '</a></span>';

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
 $info_box_contents = array();
 $info_box_contents[] = array('text' => BOX_HEADING_CATEGORIES);

 new infoBoxHeading($info_box_contents, true, false);

 $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 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'];
}
 }


 tep_show_category($first_element); 

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

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

 

any idea how to list (only) the current category beneath the <b> one?

Posted

give this a shot not sure if it will cover all the levels though: (watch the end of the code its not the whole file - left the categories comment as a marker)

 

<?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
*/

 function tep_show_category($counter) {
global $tree, $categories_string, $cPath_array;

if (isset($cPath_array) && in_array($counter, $cPath_array) || $tree[$counter]['level'] == 0 )
{

for ($i=0; $i<$tree[$counter]['level']; $i++) {
  $categories_string .= "  ";
}

$categories_string .= '<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 .= '<b>';
}

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

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

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 ($tree[$counter]['next_id'] != false ) {
  tep_show_category($tree[$counter]['next_id']);
}

 }
?>
<!-- categories //-->

Posted

did you restore your original file? (you should have the original and modify it with the last code I posted). Otherwise I'll post the whole file.

Posted

yes i restore the file once i've determined a modification to not work :)

(not sure if you mean something else?)

Posted

well ok here is the entire file:

 

<?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
*/

 function tep_show_category($counter) {
global $tree, $categories_string, $cPath_array;

if (isset($cPath_array) && in_array($counter, $cPath_array) || $tree[$counter]['level'] == 0 )
{

for ($i=0; $i<$tree[$counter]['level']; $i++) {
  $categories_string .= "  ";
}

$categories_string .= '<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 .= '<b>';
}

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

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

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 ($tree[$counter]['next_id'] != false ) {
  tep_show_category($tree[$counter]['next_id']);
}

 }
?>
<!-- categories //-->
	  <tr>
		<td>
<?php
 $info_box_contents = array();
 $info_box_contents[] = array('text' => BOX_HEADING_CATEGORIES);

 new infoBoxHeading($info_box_contents, true, false);

 $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 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 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);

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

 

if you go to a sub-category you will see the sub-category open.

Archived

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

×
×
  • Create New...