Contributions
Display Category Name In Main Content
This is a little mod that took me so long to work out (for what it is) that I couldn't not contribute it. I hope it's useful to some and at least unique.
This mod will allow you to display the name of the current category or subcategory in the main page heading, where a clean osC2.2MS would say "Let's see what we have here", in the same manner as the last category listed in the breadcrumb trail.
This would be most useful in instances where you have altered the appearance of osCommerce substantially (perhaps with Simple Template System) and require something a little more obvious on your page than the breadcrumbs or categories box as an indicator of where you are in the catalog.
Email me if anything screws up! :)
Expand All / Collapse All
Full credit for this belongs with the osCommerce knowledge base at this URL:
http://www.oscommerce.info/docs/english/e_display_category_name.html
This approach works perfectly for me. NO FILE DOWNLOAD!
INSTRUCTIONS:
In catalog/include/classes/breadcrumb.php add the following subroutine:
// start of added code for category/subcategory names
function last() { $trail_size = sizeof($this->_trail); return
$this->_trail[$trail_size-1]['title']; }
// end of added code
After this code about line 22:
function breadcrumb() {
$this->reset();
}
function reset() {
$this->_trail = array();
}
In in catalog/index.php (back it up first!), change the first 2 occurrences of HEADING_TITLE (line 76 & line 254).
From:
<td class="pageHeading"><?php echo HEADING_TITLE; ?></td>
To:
<td class="pageHeading"><?php echo $breadcrumb->last(); ?></td>
NO FILE DOWNLOAD!
enjoy.
Forgot the stupid space between the category and the parent, if there's a parent. Please forgive.
In /catalog/index.php, find this code (line 232 in clean osCommerce v2.2 MS)
<td class="pageHeading"><?php echo HEADING_TITLE; ?></td>
and change to :
<td class="pageHeading">
<?php // hacked to display current category name in main content area!
if ($tree[$current_category_id]['parent'] != '0') {
echo $tree[$tree[$current_category_id]['parent']]['name'] . ' ';
}
echo $tree[$current_category_id]['name'];
?>
Nothing to download here.
In /catalog/index.php, find this code (line 232 in clean osCommerce v2.2 MS)
<td class="pageHeading"><?php echo HEADING_TITLE; ?></td>
and change to :
<td class="pageHeading">
<?php // hacked to display current category name in main content area!
if ($tree[$current_category_id]['parent'] != '0') {
echo $tree[$tree[$current_category_id]['parent']]['name'];
}
echo $tree[$current_category_id]['name'];
?>
Nothing to download here.
Have tested and work on my website.
Can Display nested Category name left to right or right to left with seperator of your choice or even only the last name.
Usage instruction in the middle of the file.
Don't forget to drop me a email if you like it or if u have better solutions.
Nice job Nik! Great little contrib, very useful!
Just to say that the original code works fine on my MS2.2 . So here it is again :
In /catalog/index.php, find this code (line 232 in clean osCommerce v2.2 MS)
<td class="pageHeading"><?php echo HEADING_TITLE; ?></td>
and change to :
<td class="pageHeading">
<?php // hacked to display current category name in main content area!
echo $tree[$current_category_id]['name'];
?>
Nothing to download here.
There's an issue with the forums removing slashes from the file as it displayed on screen in the update below. Only use the code as copied directly from the zip file!
Nik
Oops! Minuteago pointed out this doesn't work. I contributed this but obviously changed it since.
Not sure why this got through unchecked. Sorry to all that tried this and failed.
Read the old version for the full instructions, just change the source code as below.
Regards,
Nik
Old Version (wrong):
<td class="pageHeading">
<?php
// hacked to display current category name in main content area!
echo HEADING_TITLE . $tree[$current_category_id]['name'];
?>
</td>
New version:
<td class="pageHeading">
<?php
// hacked to display current category name in main content area! Nik
echo HEADING_TITLE . ''' . $tree[$current_category_id]['name'] . ''';
?>
</td>
This is a little mod that took me so long to work out (for what it is) that I couldn't not contribute it. I hope it's useful to some and at least unique.
This mod will allow you to display the name of the current category or subcategory in the main page heading, where a clean osC2.2MS would say "Let's see what we have here", in the same manner as the last category listed in the breadcrumb trail.
This would be most useful in instances where you have altered the appearance of osCommerce substantially (perhaps with Simple Template System) and require something a little more obvious on your page than the breadcrumbs or categories box as an indicator of where you are in the catalog.
Email me if anything screws up! :)
Note: Contributions are used at own risk.