I'm building a new site using the default template (v2.3.x) and want to target a menu item in the main nav bar to apply a colour change. In order to do that I want to insert an ID into the <li id="x"></li>. Is there a simple way to insert the category ID of the menu item OR a number that can auto increment to generate a unique ID.
You can use css :nth-child() selector.
If you want to add category id to each item in menu, edit this two files:
First file
edit this part, new codes are wrapped with /* add this */ comment:
Second file
I've added id="menu-category-id<?php echo $category['category_id']; ?>" and id="menu-category-id<?php echo $child['category_id']; ?>"
If you want to add category id to each item in menu, edit this two files:
First file
Code: Select all
catalog/controller/common/header.php
Code: Select all
foreach ($categories as $category) {
if ($category['top']) {
// Level 2
$children_data = array();
$children = $this->model_catalog_category->getCategories($category['category_id']);
foreach ($children as $child) {
$filter_data = array(
'filter_category_id' => $child['category_id'],
'filter_sub_category' => true
);
$children_data[] = array(
/* add this */
'category_id' => $child['category_id'],
/* add this */
'name' => $child['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($filter_data) . ')' : ''),
'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id'])
);
}
// Level 1
$data['categories'][] = array(
/* add this */
'category_id' => $category['category_id'],
/* add this */
'name' => $category['name'],
'children' => $children_data,
'column' => $category['column'] ? $category['column'] : 1,
'href' => $this->url->link('product/category', 'path=' . $category['category_id'])
);
}
}
I've added id="menu-category-id<?php echo $category['category_id']; ?>" and id="menu-category-id<?php echo $child['category_id']; ?>"
Code: Select all
catalog/view/theme/default/template/common/header.tpl
Code: Select all
<div class="collapse navbar-collapse navbar-ex1-collapse">
<ul class="nav navbar-nav">
<?php foreach ($categories as $category) { ?>
<?php if ($category['children']) { ?>
<li id="menu-category-id<?php echo $category['category_id']; ?>" class="dropdown"><a href="<?php echo $category['href']; ?>" class="dropdown-toggle" data-toggle="dropdown"><?php echo $category['name']; ?></a>
<div class="dropdown-menu">
<div class="dropdown-inner">
<?php foreach (array_chunk($category['children'], ceil(count($category['children']) / $category['column'])) as $children) { ?>
<ul class="list-unstyled">
<?php foreach ($children as $child) { ?>
<li id="menu-category-id<?php echo $child['category_id']; ?>"><a href="<?php echo $child['href']; ?>"><?php echo $child['name']; ?></a></li>
<?php } ?>
</ul>
<?php } ?>
</div>
<a href="<?php echo $category['href']; ?>" class="see-all"><?php echo $text_all; ?> <?php echo $category['name']; ?></a> </div>
</li>
<?php } else { ?>
<li id="menu-category-id<?php echo $category['category_id']; ?>"><a href="<?php echo $category['href']; ?>"><?php echo $category['name']; ?></a></li>
<?php } ?>
<?php } ?>
</ul>
</div>
Who is online
Users browsing this forum: No registered users and 12 guests