Page 1 of 1

add category name for specific category id in header.tpl

Posted: Thu Mar 20, 2025 5:03 pm
by ianhaney50
I am trying to add the category name and link in the header.tpl for a specific category id. I have a extension installed that allows specific customer groups to access certain categories and it works and the category names/links are hidden if a customer group is not logged in and when they are logged in, they can see the category names in the menu in the header file. The client wants a link to show all the time to a specific category so non logged in members can view the category and buy products so in header.tpl I added the following code

Code: Select all

<li><a href="index.php?route=product/category&path=65">Public Shop</a></li>
But thought if they change the name of the category on the admin side and I don't know they did it, the old category name will show still so I thought if I could code in the header.tpl if a specific category id for example 65 then show the category link and category name

That way I don't have to update the name if they have changed the category name

In header.php controller file, above

Code: Select all

$categories = $this->model_catalog_category->getCategories(0);
I added

Code: Select all

$data['category_id'] = $category_id;
Then in header.tpl file I added

Code: Select all

<?php if ($category_id == '65') { ?>
          <li><a href="<?php echo $category['href']; ?>"><?php echo $category['name']; ?></a></li>
        <?php } ?>
But that didn't work, can anyone help please? I'm using 2.3.0.2. Thank you in advance

Re: add category name for specific category id in header.tpl

Posted: Thu Mar 20, 2025 7:57 pm
by paulfeakins
You might be better off finding the part in the extension that shows and hides categories and making your change in there, but generally speaking, hardcoding IDs is a nasty hack.

Re: add category name for specific category id in header.tpl

Posted: Fri Mar 21, 2025 2:27 pm
by rusy658
If the database IDs change (which can happen during database migrations, updates, or even simple re-installations),