Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Help Deciphering Some Code


gdfwilliams

Recommended Posts

I am trying to get the Category Tabs contribution to display SubCategories, but am having no luck with the code.

 

Can anyone see a quick way to hack this up to display only SUBCATEGORIES?

 

<?php

/*

 categories_tab.php V1.3

	 Displays the main categories as tabs in the header.

 osCommerce, Open Source E-Commerce Solutions

 http://www.oscommerce.com



 Copyright (c) 2002 Protelligence. 



 Released under the GNU General Public License

*/



 function show_category_tabs($counter) {

   global $foo, $categories_string, $id, $HTTP_GET_VARS;



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

      $cPath_new = 'cPath=' . $counter;

    }

   if ($HTTP_GET_VARS['cPath'] != 0){

   $base = substr($HTTP_GET_VARS['cPath'], 0, strpos($HTTP_GET_VARS['cPath'], '_'));

       if ($counter == $HTTP_GET_VARS['cPath']) {

  $onpage = 1;

  } elseif ($counter == $base) {

  $onpage = 1;

  }

   }



  if ($onpage) {

    $categories_string .= '<td valign="top" class="ontab">';

} else {

    $categories_string .= '<td valign="top" class="tab">';

     } 	 



 $categories_string .= tep_image(DIR_WS_IMAGES . 'trans_corner_left.gif', ''); 

 $categories_string .= '</td>';

       if ($onpage) {

    $categories_string .= '<td valign="top" class="ontab">';

} else {

    $categories_string .= '<td valign="top" class="tab">';

     } 	 



 $categories_string .= '<table width="100%" border="0" cellspacing="0" cellpadding="0">

	 <tr>

   <td valign="top" bgcolor="#ffffff">';

    $categories_string .= tep_image(DIR_WS_IMAGES . 'pixel_trans.gif', '');

 $categories_string .= '</td>

	 </tr>

	 <tr>

   <td valign="top" bgcolor="#C0C0C0">';

 $categories_string .= tep_image(DIR_WS_IMAGES . 'pixel_trans.gif', '');

 $categories_string .= '</td>

	 </tr>

	 </table>

        <a href="';





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

    if ($onpage) {

 $categories_string .= '"  class="ontab">';

 } else {

    $categories_string .= '" class="tab">';

     }

// display category name

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



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

  if ($onpage) {

    $categories_string .= '<td valign="top" class="ontab">';

  } else {

    $categories_string .= '<td valign="top" class="tab">';

     } 	 



 $categories_string .= tep_image(DIR_WS_IMAGES . 'trans_corner_right.gif', '');

 $categories_string .= '</td>';



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

   $onpage = 0;

      show_category_tabs($foo[$counter]['next_id']);

    }

  }

?>

<!-- categories //-->

<table border="0" cellspacing="0" cellpadding="0" bgcolor="#000080">

     <tr>

<?php



 $categories_string = '';



 $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='" . $languages_id ."' order by sort_order, cd.categories_name");

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

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

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

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

                                       'level' => 0,

                                       'path' => $categories['categories_id'],

                                       'next_id' => false

                                      );



   if (isset($prev_id)) {

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

   }



   $prev_id = $categories['categories_id'];



   if (!isset($first_element)) {

     $first_element = $categories['categories_id'];

   }

 }



 show_category_tabs($first_element); 

echo $categories_string;

?>

</tr>

</table>



<!-- categories_eof //-->

Link to comment
Share on other sites

Down and dirty solution to list each subcat w/in a category:

<?php

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

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

     $category_links = array_reverse($cPath_array);

     for($i=0; $i<sizeof($category_links); $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");

   }

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

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

     echo '<b><a href="' . tep_href_link(FILENAME_DEFAULT, $cPath_new, 'NONSSL') . '">' . $categories['categories_name'] . '</a></b>' . "n";

   }

?>

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...