Add custom link to top link next to My Account in magento 1.9
-
04-10-2020 - |
Question
this is my config file in etc\module :
<?xml version="1.0"?>
<config>
<modules>
<Net_Toplinks>
<active>true</active>
<codePool>local</codePool>
<version>0.0.1</version>
</Net_Toplinks>
</modules>
</config>
then added this code in app\code\local\net\Toplinks\etc\congif.xml
<?xml version="1.0"?>
<config>
<modules>
<Net_Toplinks>
<version>0.0.1</version>
</Net_Toplinks>
</modules>
<global>
<blocks>
<net_toplinks>
<class>Net_Toplinks_Block</class>
</net_toplinks>
</blocks>
</global>
<frontend>
<layout>
<updates>
<net_toplinks>
<file>net_toplinks.xml</file>
</net_toplinks>
</updates>
</layout>
</frontend>
</config>
Added block file as block\Stores.php
<?php
class Net_Toplinks_Block_Stores extends Mage_Core_Block_Template {
public function addCustomLinks()
{
$parentBlock = $this->getParentBlock();
if ($parentBlock )
{
$text = 'casa';
//Top link Display Text
$url = ‘testmodule’;
$position = 3;
$parentBlock->addLink($text, $url , $text, $prepare=true, $urlParams=array(), $position , null, 'class="top-link-testmodule"');
}
return $this;
}
}
?>
& finally added this in mycustom-theme folder under \app\design\frontend\net\custom-theme\layout\net_toplinks.xml
<?xml version="1.0"?>
<layout>
<default>
<reference name="top.links">
<block type="net_toplinks/stores" name="stores_links">
<action method="addCustomLinks"></action>
</block>
</reference>
</default>
</layout>
Still no link is shown in top links. Currently it shows link in Myaccount dropdown.I want link outside dropdown next to or before Account.
Solution
In header.phtml
, replace the below code under <div class="account-cart-wrapper">
<div class="account-cart-wrapper">
<a href="<?php echo $this->helper('customer')->getAccountUrl(); ?>" data-target-element="#header-account" class="skip-link skip-account">
<span class="icon"></span>
<span class="label"><?php echo $this->__('Account'); ?></span>
</a>
<!-- Custom links-->
<a href="<?php echo $this->helper('customer')->getAccountUrl(); ?>">
<span class="icon"></span>
<span class="label"><?php echo $this->__('Custom Url'); ?></span>
</a>
<!-- Cart -->
<div class="header-minicart">
<?php echo $this->getChildHtml('minicart_head'); ?>
</div>
</div>
I just the duplicate the account url choose what ever you want and change the design as well
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange