Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Categories.php/Header.php navigation menu


Clutch

Recommended Posts

Hi all, hope someone can help me out here.

 

I am trying to customize my oscommerce navigation and break down the categories listed in the menu in my left column into seperate sections while remaining in the same box. A little new to php, so I took my first crack, and started cloning code:

 

//This is an excerpt of my header.php file consisting of the categories box

<?   // ---- CATEGORIES



 function tep_show_category4($counter) {

global $tree, $categories4_string, $cPath_array;



  if(!$tree[$counter]['level']){			   



$categories4_string .= $categories4_string ? '<tr><td><img src=images/m17.gif width=223 height=1></td></tr><tr><td height=3></td></tr>' : '';



$categories4_string .= '<tr><td>  <img src=images/m16.gif width=5 height=5>  <a class=ml1 href=';



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

  $cPath_new = 'cPath=' . $counter;

} else {

  $cPath_new = 'cPath=' . $tree[$counter]['path'];

}

$categories4_string .= tep_href_link('index.php', $cPath_new) . '>';

// display categry name

$categories4_string .= $tree[$counter]['name'];

$categories4_string .= '</a></td></tr><tr><td height=3></td></tr>

';



  }else{  // SUBcategory4



$categories4_string .= '<tr><td>    ';



for($i=0;$i<$tree[$counter]['le vel'];$i++)

 $categories4_string .= '   ';



$categories4_string .= ' - <a class=ml1 style="font-weight:normal;" href=';

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

  $cPath_new = 'cPath=' . $counter;

} else {

  $cPath_new = 'cPath=' . $tree[$counter]['path'];

}

$categories4_string .= tep_href_link('index.php', $cPath_new) . '>';

// display category4 name

$categories4_string .= $tree[$counter]['name'];

$categories4_string .= '</a></td></tr><tr><td height=3></td></tr>';

  }



if ($tree[$counter]['next_id'] != false) {

  tep_show_category4($tree[$counter]['next_id']);

}

 }







 define(TABLE_categories4, "categories4");

 define(TABLE_categories4_DESCRIPTION, "categories4_description");

 $categories4_string = '';

 $tree = array();



 $categories4_query = tep_db_query("select c.categories4_id, cd.categories4_name, c.parent_id from " . TABLE_categories4 . " c, " . TABLE_categories4_DESCRIPTION . " cd where c.parent_id = '0' and c.categories4_id = cd.categories4_id and cd.language_id='" . (int)$languages_id ."' order by sort_order, cd.categories4_name");

 while ($categories4 = tep_db_fetch_array($categories4_query))  {

$tree[$categories4['categories4_id']] = array('name' => $categories4['categories4_name'],

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

											'level' => 0,

											'path' => $categories4['categories4_id'],

											'next_id' => false);



if (isset($parent_id)) {

  $tree[$parent_id]['next_id'] = $categories4['categories4_id'];

}



$parent_id = $categories4['categories4_id'];



if (!isset($first_element)) {

  $first_element = $categories4['categories4_id'];

}

 }



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

 if ($cPath) {

$new_path = '';

reset($cPath_array);

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

  unset($parent_id);

  unset($first_id);

  $categories4_query = tep_db_query("select c.categories4_id, cd.categories4_name, c.parent_id from " . TABLE_categories4 . " c, " . TABLE_categories4_DESCRIPTION . " cd where c.parent_id = '" . (int)$value . "' and c.categories4_id = cd.categories4_id and cd.language_id='" . (int)$languages_id ."' order by sort_order, cd.categories4_name");

  if (tep_db_num_rows($categories4_query)) {

	$new_path .= $value;

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

	  $tree[$row['categories4_id']] = array('name' => $row['categories4_name'],

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

										   'level' => $key+1,

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

										   'next_id' => false);



	  if (isset($parent_id)) {

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

	  }



	  $parent_id = $row['categories4_id'];



	  if (!isset($first_id)) {

		$first_id = $row['categories4_id'];

	  }



	  $last_id = $row['categories4_id'];

	}

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

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

	$new_path .= '_';

  } else {

	break;

  }

}

 }

 $categories4_string .=  '';

 tep_show_category4($first_element);

 $categories4_string .=  '';



 echo $categories4_string;

?>

				   <tr><td height=7></td></tr>
				  </table>

													 <table cellspacing=0 cellpadding=0 width=223 align=center>

				   <tr><td height=14></td></tr>

				   <tr><td><img src=images/m14a.gif width=136 height=23></td></tr>

				   <tr><td><img src=images/m15.gif width=223 height=2></td></tr>

				   <tr><td height=10></td></tr>
				   <?

function tep_show_category2($counter) {

global $tree, $categories2_string, $cPath_array;



  if(!$tree[$counter]['level']){



$categories2_string .= $categories2_string ? '<tr><td><img src=images/m17.gif width=223 height=1></td></tr><tr><td height=3></td></tr>' : '';



$categories2_string .= '<tr><td>  <img src=images/m16.gif width=5 height=5>  <a class=ml1 href=';



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

  $cPath_new = 'cPath=' . $counter;

} else {

  $cPath_new = 'cPath=' . $tree[$counter]['path'];

}

$categories2_string .= tep_href_link('index.php', $cPath_new) . '>';

// display categry name

$categories2_string .= $tree[$counter]['name'];

$categories2_string .= '</a></td></tr><tr><td height=3></td></tr>

';




  }else{  // SUBCATEGORY



$categories2_string .= '<tr><td>    ';



for($i=0;$i<$tree[$counter]['le vel'];$i++)

 $categories2_string .= '   ';



$categories2_string .= ' - <a class=ml1 style="font-weight:normal;" href=';

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

  $cPath_new = 'cPath=' . $counter;

} else {

  $cPath_new = 'cPath=' . $tree[$counter]['path'];

}

$categories2_string .= tep_href_link('index.php', $cPath_new) . '>';

// display category name

$categories2_string .= $tree[$counter]['name'];

$categories2_string .= '</a></td></tr><tr><td height=3></td></tr>';

  }



if ($tree[$counter]['next_id'] != false) {

  tep_show_category2($tree[$counter]['next_id']);

}

 }


 define(TABLE_categories2, "categories2");

 define(TABLE_categories2_DESCRIPTION, "categories2_description");

 $categories2_string = '';

 $tree = array();



 $categories2_query = tep_db_query("select c.categories2_id, cd.categories2_name, c.parent_id from " . TABLE_categories2 . " c, " . TABLE_categories2_DESCRIPTION . " cd where c.parent_id = '0' and c.categories2_id = cd.categories2_id and cd.language_id='" . (int)$languages_id ."' order by sort_order, cd.categories2_name");

 while ($categories2 = tep_db_fetch_array($categories2_query))  {

$tree[$categories2['categories2_id']] = array('name' => $categories2['categories2_name'],

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

											'level' => 0,

											'path' => $categories2['categories2_id'],

											'next_id' => false);



if (isset($parent_id)) {

  $tree[$parent_id]['next_id'] = $categories2['categories2_id'];

}



$parent_id = $categories2['categories2_id'];



if (!isset($first_element)) {

  $first_element = $categories2['categories2_id']+1;

}

 }



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

 if ($cPath) {

$new_path = '';

reset($cPath_array);

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

  unset($parent_id);

  unset($first_id);

  $categories2_query = tep_db_query("select c.categories2_id, cd.categories2_name, c.parent_id from " . TABLE_categories2 . " c, " . TABLE_categories2_DESCRIPTION . " cd where c.parent_id = '" . (int)$value . "' and c.categories2_id = cd.categories2_id and cd.language_id='" . (int)$languages_id ."' order by sort_order, cd.categories2_name");

  if (tep_db_num_rows($categories2_query)) {

	$new_path .= $value;

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

	  $tree[$row['categories2_id']] = array('name' => $row['categories2_name'],

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

										   'level' => $key+1,

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

										   'next_id' => false);



	  if (isset($parent_id)) {

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

	  }



	  $parent_id = $row['categories2_id'];



	  if (!isset($first_id)) {

		$first_id = $row['categories2_id'];

	  }



	  $last_id = $row['categories2_id'];

	}

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

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

	$new_path .= '_';

  } else {

	break;

  }

}

 }

 $categories2_string .=  '';

 tep_show_category2($first_element);

 $categories2_string .=  '';



 echo $categories2_string;

?>
	  <tr><td height=7></td></tr>
				  </table>

													 <table cellspacing=0 cellpadding=0 width=223 align=center>

				   <tr><td height=14></td></tr>

				   <tr><td><img src=images/m14b.gif width=136 height=23></td></tr>

				   <tr><td><img src=images/m15.gif width=223 height=2></td></tr>

				   <tr><td height=10></td></tr>
				   <?

function tep_show_category3($counter) {

global $tree, $categories3_string, $cPath_array;



  if(!$tree[$counter]['level']){



$categories3_string .= $categories3_string ? '<tr><td><img src=images/m17.gif width=223 height=1></td></tr><tr><td height=3></td></tr>' : '';



$categories3_string .= '<tr><td>  <img src=images/m16.gif width=5 height=5>  <a class=ml1 href=';



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

  $cPath_new = 'cPath=' . $counter;

} else {

  $cPath_new = 'cPath=' . $tree[$counter]['path'];

}

$categories3_string .= tep_href_link('index.php', $cPath_new) . '>';

// display categry name

$categories3_string .= $tree[$counter]['name'];

$categories3_string .= '</a></td></tr><tr><td height=3></td></tr>

';




  }else{  // SUBCATEGORY



$categories3_string .= '<tr><td>    ';



for($i=0;$i<$tree[$counter]['le vel'];$i++)

 $categories3_string .= '   ';



$categories3_string .= ' - <a class=ml1 style="font-weight:normal;" href=';

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

  $cPath_new = 'cPath=' . $counter;

} else {

  $cPath_new = 'cPath=' . $tree[$counter]['path'];

}

$categories3_string .= tep_href_link('index.php', $cPath_new) . '>';

// display category name

$categories3_string .= $tree[$counter]['name'];

$categories3_string .= '</a></td></tr><tr><td height=3></td></tr>';

  }



if ($tree[$counter]['next_id'] != false) {

  tep_show_category3($tree[$counter]['next_id']);

}

 }


 define(TABLE_categories3, "categories3");

 define(TABLE_categories3_DESCRIPTION, "categories3_description");

 $categories3_string = '';

 $tree = array();



 $categories3_query = tep_db_query("select c.categories3_id, cd.categories3_name, c.parent_id from " . TABLE_categories3 . " c, " . TABLE_categories3_DESCRIPTION . " cd where c.parent_id = '0' and c.categories3_id = cd.categories3_id and cd.language_id='" . (int)$languages_id ."' order by sort_order, cd.categories3_name");

 while ($categories3 = tep_db_fetch_array($categories3_query))  {

$tree[$categories3['categories3_id']] = array('name' => $categories3['categories3_name'],

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

											'level' => 0,

											'path' => $categories3['categories3_id'],

											'next_id' => false);



if (isset($parent_id)) {

  $tree[$parent_id]['next_id'] = $categories3['categories3_id'];

}



$parent_id = $categories3['categories3_id'];



if (!isset($first_element)) {

  $first_element = $categories3['categories3_id'];

}

 }



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

 if ($cPath) {

$new_path = '';

reset($cPath_array);

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

  unset($parent_id);

  unset($first_id);

  $categories3_query = tep_db_query("select c.categories3_id, cd.categories3_name, c.parent_id from " . TABLE_categories3 . " c, " . TABLE_categories3_DESCRIPTION . " cd where c.parent_id = '" . (int)$value . "' and c.categories3_id = cd.categories3_id and cd.language_id='" . (int)$languages_id ."' order by sort_order, cd.categories3_name");

  if (tep_db_num_rows($categories3_query)) {

	$new_path .= $value;

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

	  $tree[$row['categories3_id']] = array('name' => $row['categories3_name'],

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

										   'level' => $key+1,

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

										   'next_id' => false);



	  if (isset($parent_id)) {

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

	  }



	  $parent_id = $row['categories3_id'];



	  if (!isset($first_id)) {

		$first_id = $row['categories3_id'];

	  }



	  $last_id = $row['categories3_id'];

	}

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

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

	$new_path .= '_';

  } else {

	break;

  }

}

 }

 $categories3_string .=  '';

 tep_show_category3($first_element);

 $categories3_string .=  '';



 echo $categories3_string;

?>

 

I have also cloned the category tables and all works fine, all 3 menu sections list with no breaks in the breadcrumb. I removed the unnecessary products and categories from the cloned tables, but when I go to remove the first id from the either of the new tables, the new menu section from which i've removed the ID breaks. The menu dissapears, all except for the first arrow.

 

Any ideas? =\ Thanks in advance!

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...