OpenCart Main Category


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <?php
  2. $top_cat_id = '';
  3. if (isset($this->request->get['path'])) {
  4. $path = $this->request->get['path'];
  5. $cat_array = explode ("_", $path);
  6. $top_cat_id = $cat_array[0];
  7. }
  8.  
  9. $this->load->model('tool/seo_url');
  10.  
  11. $results = $this->model_catalog_category->getCategories();
  12.  
  13. if ($results) {
  14. $output = '<ul>';
  15. }
  16.  
  17. foreach ($results as $result) {
  18. $new_path = $result['category_id'];
  19. $unrewritten = HTTP_SERVER.'index.php?route=product/category&path=' . $new_path;
  20. $rewritten = $this->model_tool_seo_url->rewrite($unrewritten);
  21. if ($new_path == $top_cat_id) {
  22. $output .= '<li id="current-cat"><a href="'.str_replace('&', '&amp;', $rewritten).'">'.$result['name'].'</a>';
  23. } else {
  24. $output .= '<li><a href="'.str_replace('&', '&amp;', $rewritten).'">'.$result['name'].'</a>';
  25. }
  26.  
  27. $output .= '</li>';
  28. }
  29.  
  30. if ($results) {
  31. $output .= '</ul>';
  32. }
  33.  
  34. echo $output;
  35. ?>

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.