Post by ianhaney50 » Thu Mar 20, 2025 5:03 pm

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

Active Member

Posts

Joined
Fri Apr 29, 2016 4:21 am

Post by paulfeakins » Thu Mar 20, 2025 7:57 pm

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.

UK OpenCart Hosting | OpenCart Audits | OpenCart Support - please email info@antropy.co.uk


User avatar
Guru Member
Online

Posts

Joined
Mon Aug 22, 2011 11:01 pm
Location - London Gatwick, United Kingdom

Post by rusy658 » Fri Mar 21, 2025 2:27 pm

If the database IDs change (which can happen during database migrations, updates, or even simple re-installations),

Newbie

Posts

Joined
Thu Mar 20, 2025 5:28 pm
Who is online

Users browsing this forum: Majestic-12 [Bot] and 151 guests