In order to be semantic it should be...
Code: Select all
<ul>
<li><a href="#">Link</a>
<ul>
<li><a href="#">Link</a>
<ul>
<li><a href="#">Link</a>
</ul>
</li>
</ul>
</li>
</ul>
http://craigmurray.me.uk/opencart-mods/ ... -opencart/
I've taken that which only supports 2 levels and hacked it somewhat. Without even considering the implications of code standard i dare to submit it below.
Hope it's useful to someone.
Code: Select all
$this->load->model('tool/seo_url');
$results = $this->model_catalog_category->getCategories();
if($results)
{
$output = '<ul>';
}
$output .= '<li><a href="/">Home</a></li>';
$counter = 0;
foreach ($results as $result)
{
// HTML
$output .= '<li class="nav-item-'.$counter.'">';
// Grab the specific category, reset each loop
$new_path = $result['category_id'];
// Prepare the URL
$unrewritten = HTTP_SERVER.'index.php?route=product/category&path=' . $new_path;
// Pass it to the SEO URL tool
$rewritten = $this->model_tool_seo_url->rewrite($unrewritten);
// Output the path and category name
$output .= '<a href="' . $rewritten . '">' . $result['name'] . '</a>';
$counter++;
// Next level deep with the current category as the parameter.
// Children of
$sub_results = $this->model_catalog_category->getCategories($new_path);
// If there are subs
if ($sub_results)
{
// HTML
$output .= '<ul>';
}
foreach ($sub_results as $sub_result)
{
// HTML
$output .= '<li>';
// Allocate the new sub category
$new_sub_path = $sub_result['category_id'];
// Get the raw URL and prepare it
$sub_unrewritten = $unrewritten.'_'. $new_sub_path;
// Rewrite it
$sub_rewritten = $this->model_tool_seo_url->rewrite($sub_unrewritten);
// Output as usual
$output .= '<a href="' . $sub_rewritten . '">' . $sub_result['name'] . '</a>';
// Grab the specific category, reset each loop
$new_sub_path = $sub_result['category_id'];
// Next level deep with the current category as the parameter.
// Children of
$sub_sub_results = $this->model_catalog_category->getCategories($new_sub_path);
// If there are subs
if ($sub_sub_results)
{
// HTML
$output .= '<ul class="sub-sub-results">';
}
else
{
$output .= '</li>';
}
$counter2 = 0;
foreach ($sub_sub_results as $sub_sub_result)
{
// HTML
$output .= '<li class="sub-nav-item-'.$counter2.'">';
// Allocate the new sub category
$new_sub_path = $sub_result['category_id'];
// Get the raw URL and prepare it
$sub_sub_unrewritten = $unrewritten.'_'. $new_sub_path;
// Rewrite it
$sub_sub_rewritten = $this->model_tool_seo_url->rewrite($sub_sub_unrewritten);
// Output as usual
$output .= '<a href="' . $sub_sub_rewritten . '">' . $sub_sub_result['name'] . '</a>';
$output .= '</li>';
$counter2++;
}
if ($sub_sub_results)
{
// Close off children UL
$output .= '</ul>';
}
$output .= '</li>';
}
if ($sub_results)
{
// Close off children UL
$output .= '</ul>';
}
}
if ($results)
{
// Close parent UL
$output .= '</ul>';
}
echo $output;