Can I disable 'javascript:void' in categories to preserve category click?
Hey there,
I would like to preserve in my sidebar navigation the ability to click at anytime the subcategory to be able to go back to the product array (i.e. the page with all the products photos in their respective sub-category). Right now when a customer is in a product detail page, the sidebar navigation link to go back is turned off with a "javascript:void(0)"
Since I'm not very good with php, how would I change the line of code in the "categories_ul_generator.php" file so it doesn't create a null link? Thanks for any help!
Code:
function buildBranch($parent_id, $level = 0, $cpath = '') {
global $cPath;
$result = "\n".sprintf($this->parent_group_start_string, str_repeat(' ', $level*4))."\n";
if (isset($this->data[$parent_id])) {
foreach ($this->data[$parent_id] as $category_id => $category) {
$result .= sprintf($this->child_start_string, str_repeat(' ', $level*4+2));
if (isset($this->data[$category_id])) {
$result .= $this->parent_start_string;
}
if ($level == 0) {
$result .= $this->root_start_string;
$new_cpath = $category_id;
} else {
$new_cpath = $cpath."_".$category_id;
}
if ($cPath == $new_cpath) {
$result .= '<a href="javascript:void(0)" class="on">'; // highlight current category & disable link
} else {
$result .= '<a href="' . zen_href_link(FILENAME_DEFAULT, 'cPath=' . $new_cpath) . '">';
}
$result .= $category['name'];
if (SHOW_COUNTS == 'true' && ((CATEGORIES_COUNT_ZERO == '1' && $category['count'] == 0) || $category['count'] >= 1)) {
$result .= CATEGORIES_COUNT_PREFIX . $category['count'] . CATEGORIES_COUNT_SUFFIX;
}
$result .= '</a>';
if ($level == 0) {
$result .= $this->root_end_string;
}
if (isset($this->data[$category_id])) {
$result .= $this->parent_end_string;
}
if (isset($this->data[$category_id]) && (($this->max_level == '0') || ($this->max_level > $level+1))) {
$result .= $this->buildBranch($category_id, $level+1, $new_cpath);
$result .= sprintf($this->child_end_string, str_repeat(' ', $level*4+2))."\n";
} else {
$result .= sprintf($this->child_end_string, '')."\n";
}
}
}
$result .= sprintf($this->parent_group_end_string, str_repeat(' ', $level*4))."\n";
return $result;
}
Re: Can I disable 'javascript:void' in categories to preserve category click?
I tried just replacing this line:
Code:
$result .= '<a href="javascript:void(0)" class="on">'; // highlight current category & disable link
with the next line:
Code:
$result .= '<a href="' . zen_href_link(FILENAME_DEFAULT, 'cPath=' . $new_cpath) . '">';
But this only works for one page, and then it starts spewing code! Any ideas? I don't think I can just remove that portion because it is actually building a link...
Re: Can I disable 'javascript:void' in categories to preserve category click?
Nobody has had to do this before?
Re: Can I disable 'javascript:void' in categories to preserve category click?
This is not part of core Zen Cart, so you will need to identify exactly where you got the code/mod and probably let us see it live if we are to advise on how best to change it.
Re: Can I disable 'javascript:void' in categories to preserve category click?
My first guess at what may work would be essentially as you said you did, but preserving the class so the current category remains highlighted:
PHP Code:
if ($cPath == $new_cpath) {
$result .= '<a href="' . zen_href_link(FILENAME_DEFAULT, 'cPath=' . $new_cpath) . '" class="on">'; // highlight current category
} else {
$result .= '<a href="' . zen_href_link(FILENAME_DEFAULT, 'cPath=' . $new_cpath) . '">';
}
Re: Can I disable 'javascript:void' in categories to preserve category click?
Yessir that worked. I did add the class before, but I have a feeling I didn't follow the correct php procedure for including the class correctly! Thank you so much for you help!