Sunday, April 20, 2008

Add Category Name To Product Info Pages

There is a very simple way to add the category name to the product info pages in osCommerce. Here's how:

In functions/general.php add the following code:


//// Return categories name
// TABLES: categories_description
function tep_get_categories_name($who_am_i) {
global $languages_id;

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

$the_categories_name = tep_db_fetch_array($the_categories_name_query);

return $the_categories_name['categories_name'];

}

////


Now you should be able to drop the category name into your product_info.php wherever you'd like using the following:

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



Of course the simplest way to implement the code is to add it just after the products name, like this:

<td class="pageHeading" valign="top"><?php echo $products_name; ?> - <?php echo tep_get_categories_name($current_category_id);?></td>

Which displays this on your product info page:

Product Name - Category Name

No comments: