In this tutorial we will show you a quick example of how you can edit a OpenCart template to change the default layout that is used for your OpenCart site. As an example let’s say you have created a gift voucher in OpenCart. By default it’s just going to show a link for customers to redeem their gift voucher at the bottom of the page in your site map. If you don’t have your categories menu at the top filled all the way up, adding a link to your gift vouchers in this menu might be handy for your customers.
Edit the OpenCart header template
By default when you install OpenCart all of the templates will be located in the following directory:
/catalog/view/theme/default/template/
- Open up the File Manager Code Editor in cPanel.
Navigate to the following directory in the File Manager:
/catalog/view/theme/default/template/common/
- Right click on the header.tpl file and select Code Edit.
If the encoding check pop-up displays, you can simply click Edit
Around line 93 will be where the menu at at the top of your page completes. You’ll want to insert a link to your gift voucher page here. The link you’ll want to use should look like this:
<p> <span class="code_block"></span></p>
</li><li><a href="./index.php?route=account/voucher">Gift Voucher</a></li>
<p> </p>
<p>The section of code that you're adding this to is the <strong>DIV</strong> with the ID
<strong>menu</strong>, the full code once you're done should look like this:</p>
<pre>
</p><div id="menu"> <p></p>
<ul> <!--?php foreach ($categories as $category) { ?--> <p></p>
<li><a href="<?php echo $category['href']; ?>"><!--?php echo $category['name']; ?--></a>
<br> <!--?php if ($category['children']) { ?-->
<div> <!--?php for ($i = 0; $i < count($category['children']);) { ?--> <p></p>
<ul> <!--?php $j = $i + ceil(count($category['children']) / $category['column']); ?--><br> <!--?php for (; $i < $j; $i++) { ?--><br> <!--?php if (isset($category['children'][$i])) { ?--> <p></p>
<li><a href="<?php echo $category['children'][$i]['href']; ?>"><!--?php echo $category['children'][$i]['name']; ?--></a></li>
<p> <!--?php } ?--><br> <!--?php } ?--> </p></ul>
<p> <!--?php } ?--> </p></div>
<p> <!--?php } ?--> </p></li>
<p> <!--?php } ?--><br> <strong></strong></p><strong>
<li><a href="./index.php?route=account/voucher">Gift Voucher</a></li>
</strong><p><strong></strong> </p></ul>
</div>
Once you’re done making your modification, click on Save Changes at the top right.
Now you should have a nice visible link to your gift vouchers right in your top menu, instead of tucked away down in the bottom menu. Here is a before and after showing what this change accomplished:
Before |
After |
|
|