Return to Snippet

Revision: 46252
at June 30, 2011 22:57 by odenijs


Updated Code
<?php
	$top_cat_id = '';
	if (isset($this->request->get['path'])) {
		$path = $this->request->get['path'];
		$cat_array = explode ("_", $path);
		$top_cat_id = $cat_array[0];
	}

	$this->load->model('tool/seo_url');
	
	$results = $this->model_catalog_category->getCategories();

	if ($results) {
		$output = '<ul>';
	}

	foreach ($results as $result) {
		$new_path = $result['category_id'];
		$unrewritten = HTTP_SERVER.'index.php?route=product/category&path=' . $new_path;
		$rewritten = $this->model_tool_seo_url->rewrite($unrewritten);
		if ($new_path == $top_cat_id) {
			$output .= '<li id="current-cat"><a href="'.str_replace('&', '&amp;', $rewritten).'">'.$result['name'].'</a>';
		} else {
			$output .= '<li><a href="'.str_replace('&', '&amp;', $rewritten).'">'.$result['name'].'</a>';
		}

		$output .= '</li>';
	}

	if ($results) {
		$output .= '</ul>';
	}
	
	echo $output;
?>

Revision: 46251
at May 14, 2011 23:23 by odenijs


Initial Code
<?php
$top_cat_id = '';
if (isset($this->request->get['path'])) {
$path = $this->request->get['path'];
$cat_array = explode ("_", $path);
$top_cat_id = $cat_array[0];
}
$this->load->model('tool/seo_url');
$results = $this->model_catalog_category->getCategories();
if ($results) {$output = '<ul>';}
foreach ($results as $result) {
$new_path = $result['category_id'];
$unrewritten = HTTP_SERVER.'index.php?route=product/category&path=' . $new_path;
$rewritten = $this->model_tool_seo_url->rewrite($unrewritten);
if ($new_path == $top_cat_id) {
$output .= '<li id="current-cat"><a href="'.str_replace('&', '&amp;', $rewritten).'">'.$result['name'].'</a>';
} else {
$output .= '<li><a href="'.str_replace('&', '&amp;', $rewritten).'">'.$result['name'].'</a>';
}
$output .= '</li>';
}
if ($results) {$output .= '</ul>';}
echo $output;

Initial URL
http://craigmurray.me.uk/opencart-mods/how-to-highlight-the-current-category-in-the-header-in-opencart/

Initial Description

                                

Initial Title
OpenCart Main Category

Initial Tags
category

Initial Language
PHP