Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

how to show Category name?


ANRON

Recommended Posts

As Christian said, difficult to help without more info, but a quick search reveals:

 

http://www.oscommerce.com/forums/viewtopic.php?t=31244

 

which should be easily changable to your needs.

 

this one i tried it already...but i need it show deeper category name!!

i meat $cPath=??? ...."???"=category name inside the current category..

so can anyone help me about this....

friendly everyone around th world!!

Link to comment
Share on other sites

Once again, where do you want it to show deeper categories? If you just want to show the sub-categories etc. in the categories box that is relatively easy. If it somewhere else, you should be able to modify a few different contributions to make it work. I made the categories box expand to show sub-categories here: www.diyreef.com/development/catalog/default.php

 

The more information you provide the more likely someone will be able to help you. :wink:

Link to comment
Share on other sites

Once again, where do you want it to show deeper categories? If you just want to show the sub-categories etc. in the categories box that is relatively easy. If it somewhere else, you should be able to modify a few different contributions to make it work. I made the categories box expand to show sub-categories here: www.diyreef.com/development/catalog/default.php

 

The more information you provide the more likely someone will be able to help you. :wink:

thank a lot first!!

hmm....ok!!for exam..in your wed site...

the Hardware there are include cd-rom drives,graphics,keyboards...and else!!

how can i make this!!

when i choose a product in cd-rom drives..how to make it show "catagory:cd-rom drives"!!and when i choose other product in maybe keyboards...it can show "catagory:keyboards"...in product_info.php

 

this is my code:

 

in general.php

 

function tep_get_categories_name($cPath) {

$categories_query = tep_db_query("SELECT categories_name FROM " . TABLE_CATEGORIES_DESCRIPTION . " WHERE categories_id = '" . $cPath . "'");

$products_category = tep_db_fetch_array($categories_query);

 

return ($products_category['categories_name'] == "" ? "" : $products_category['categories_name']);

 

in product_info.php:

<?php echo tep_get_categories_name($cPath); ?>

 

it can only shows "catagory:Hardware"

 

so it is confuse me !!! anyone knows?

friendly everyone around th world!!

Link to comment
Share on other sites

Once again, where do you want it to show deeper categories? If you just want to show the sub-categories etc. in the categories box that is relatively easy. If it somewhere else, you should be able to modify a few different contributions to make it work. I made the categories box expand to show sub-categories here: www.diyreef.com/development/catalog/default.php

 

The more information you provide the more likely someone will be able to help you. :wink:

thank a lot first!!

hmm....ok!!for exam..in your wed site...

the Hardware there are include cd-rom drives,graphics,keyboards...and else!!

how can i make this!!

when i choose a product in cd-rom drives..how to make it show "catagory:cd-rom drives"!!and when i choose other product in maybe keyboards...it can show "catagory:keyboards"...in product_info.php

 

this is my code:

 

in general.php

 

function tep_get_categories_name($cPath) {

$categories_query = tep_db_query("SELECT categories_name FROM " . TABLE_CATEGORIES_DESCRIPTION . " WHERE categories_id = '" . $cPath . "'");

$products_category = tep_db_fetch_array($categories_query);

 

return ($products_category['categories_name'] == "" ? "" : $products_category['categories_name']);

 

in product_info.php:

<?php echo tep_get_categories_name($cPath); ?>

 

it can only shows "catagory:Hardware"

 

so it is confuse me !!! anyone knows?

 

anyone can help me about this...?please!!!

friendly everyone around th world!!

Link to comment
Share on other sites

This should not be all that hard. Here is the code for the categories box.

<?php



 function preorder($cid, $level, $foo, $cpath)

 {

   global $categories_string, $HTTP_GET_VARS;



   if ($cid != 0) {

     for ($i=0; $i<$level; $i++)

       $categories_string .=  '  ';

     $categories_string .= '<a href="' . tep_href_link(FILENAME_DEFAULT, 'cPath

=' . $cpath . $cid) . '">';

//Are we on the "path" to selected category?

     $bold = strstr($HTTP_GET_VARS['cPath'], $cpath . $cid . '_') ||  $HTTP_GET_VARS['cPath'] == $cpath . $cid;

// If yes, use <b>

     if ($bold)

       $categories_string .=  '<b>';

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

     if ($bold)

       $categories_string .=  '</b>';

     $categories_string .=  '</a>';

// SHOW_COUNTS is 'true' or 'false', not true or false

     if (SHOW_COUNTS == 'true') {

       $products_in_category = tep_count_products_in_category($cid);

       if ($products_in_category > 0) {

         $categories_string .= ' (' . $products_in_category . ')';

       }

     }

     $categories_string .= '<br>';

   }



// Traverse category tree- this is for older snapshots pre-November 2002

/*    foreach ($foo as $key => $value) {

     if ($foo[$key]['parent'] == $cid) {

//        print "$key, $level, $cid, $cpath<br>";

       preorder($key, $level+1, $foo, ($level != 0 ? $cpath . $cid . '_' : ''))
;

     } */

// Function used for post November 2002 snapshots

 function tep_show_category($counter) {

   global $foo, $categories_string, $id;



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

     $categories_string .= "  ";

   }

   }

 }



?>

<!-- show_subcategories //-->

         <tr>

           <td>



<?php

//////////

// Display box heading

//////////

 $info_box_contents = array();

 $info_box_contents[] = array('align' => 'left', 'text'  => BOX_HEADING_CATEGORIES);

 new infoBoxHeading($info_box_contents, true, false);





//////////

// Get categories list

//////////

// Test for presence of status field for compatibility with older versions

//  $status = tep_db_num_rows(tep_db_query('describe categories status')); used for older snapshots

$status = tep_db_num_rows(tep_db_query('describe ' .  TABLE_CATEGORIES . ' status'));





 $query = "select c.categories_id, cd.categories_name, c.parent_id, c.categories_image

           from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd

           where c.categories_id = cd.categories_id";



 if ($status >0)

   $query.= " and c.status = '1'";

 $query.= " and cd.language_id='" . $languages_id ."'

           order by sort_order, cd.categories_name";



 $categories_query = tep_db_query($query);





 $categories_string = '';

 preorder(0, 0, $foo, '');



//////////

// Display box contents

//////////

 $info_box_contents = array();

 $row = 0;

 $col = 0;

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

  if ($categories['parent_id'] == 0) {

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

   $subcategories_query = tep_db_query($query);

    while ($subcategories = tep_db_fetch_array($subcategories_query)) {

               if ($subcategories['parent_id'] == $categories['categories_id'])

{

               $cPath_new_sub = "cPath="  . $categories['categories_id'] . "_" . $subcategories['categories_id'];



               $text_subcategories .= '<a href="' . tep_href_link(FILENAME_DEFAULT, $cPath_new_sub, 'NONSSL') . '"><br>' . $subcategories['categories_name'] . '</a>' . " ";

               } // if

    } // While Interno

   $info_box_contents[$row] = array('align' => 'left',

                                          'params' => 'class="smallText" width="125" valign="top"',

                                          'text' => '<a href="' . tep_href_link

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

   $col ++;

   if ($col > 0) {

     $col = 0;

     $row ++;

   }

  }

 }

 new infoBox($info_box_contents);

?>

           </td>

         </tr>

<!-- show_subcategories_eof //-->

 

This was just a slight modification to Gustavo Barreto's Main Categories contribution (I just removed the images and placed the text in a box).

 

Next, to get the sub-categories to show on your pages you should be able to take a look at this and just expand it a little. This places the category name on the page instead of "Let's see what we have here"

 

<?php 

 function tep_get_category_name($category_id) { 

   global $languages_id; 



   $category_query = tep_db_query("select categories_name from " . TABLE_CATEGORIES_DESCRIPTION . " where categories_id = '" . $category_id . "' and language_id = '" . $languages_id . "'"); 

   $category = tep_db_fetch_array($category_query); 



   return $category['categories_name']; 

 } 



 echo tep_get_category_name($current_category_id); 

?>

 

It will take a bit of work, but it should be do-able. HTH

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...