Skip to content

Instantly share code, notes, and snippets.

@jasontipton
Last active December 23, 2020 16:49
Show Gist options
  • Save jasontipton/d5421b21514a3d5030ad to your computer and use it in GitHub Desktop.
Save jasontipton/d5421b21514a3d5030ad to your computer and use it in GitHub Desktop.
Reorder and Add Class to Top.Links - Magento 1.9 Community Edition
<?xml version="1.0"?>
<!--
[Your site name] XML overrides
-->
<layout version="0.1.0">
<!-- updating top.links to add class names -->
<!-- Section 1: Removing Current Links -->
<default>
<reference name="top.links">
<!-- Removes 'My Account' link -->
<action method="removeLinkByUrl"><url helper="customer/getAccountUrl"/></action>
<!-- Removes 'My Cart' AND 'Checkout' links -->
<remove name="checkout_cart_link" />
</reference>
</default>
<customer_logged_out>
<!-- Removes 'Log In' link -->
<reference name="top.links">
<action method="removeLinkByUrl"><url helper="customer/getLoginUrl"/></action>
</reference>
</customer_logged_out>
<customer_logged_in>
<!-- Removes 'Log Out' link -->
<reference name="top.links">
<action method="removeLinkByUrl"><url helper="customer/getLogoutUrl"/></action>
</reference>
</customer_logged_in>
<!-- Section 2: Adding New Links -->
<!-- order can be easily edited here by changing the position number -->
<default>
<reference name="top.links">
<!-- add My Account -->
<!-- default position 10 -->
<action method="addLink" translate="label title" module="customer">
<label>My Account</label>
<url helper="customer/getAccountUrl"/>
<title>My Account</title>
<prepare/>
<urlParams/>
<position>10</position>
<liParams>
<class>top-account</class>
</liParams>
<aParams>
<class>top-account-a</class>
</aParams>
<beforeText/>
<afterText/>
</action>
<!-- add My Wishlist -->
<!-- default position 20 -->
<reference name="wishlist_link">
<action method="setLiParams"><params>class="top-wishlist"</params></action>
<action method="setAParams"><params>class="top-wishlist-a"</params></action>
</reference>
<!-- add My Cart -->
<!-- default position 40 -->
<block type="checkout/links" name="checkout_cart_link_custom">
<action method="addCartLink"></action>
</block>
<!-- add Checkout -->
<!-- default position 50 -->
<action method="addLink" translate="label title">
<label>Checkout</label>
<url>/checkout</url>
<title>Checkout</title>
<prepare />
<urlParams/>
<position>50</position>
<liParams>
<class>top-checkout</class>
</liParams>
<aParams>
<class>top-checkout-a</class>
</aParams>
<beforeText />
<afterText />
</action>
</reference>
</default>
<customer_logged_out>
<!-- add Log In (when customer is not logged in) -->
<reference name="top.links">
<action method="addLink" translate="label title" module="customer">
<label>Log In</label>
<url helper="customer/getAccountUrl"/>
<title>Log In</title>
<prepare/>
<urlParams/>
<position>70</position>
<liParams>
<class>top-log-in</class>
</liParams>
<aParams>
<class>top-log-in-a</class>
</aParams>
<beforeText />
<afterText />
</action>
</reference>
<!-- add Register (when customer is not logged in) -->
<reference name="top.links">
<action method="addLink" translate="label title" module="customer">
<label>Register</label>
<url helper="customer/getRegisterUrl"/>
<title>Register</title>
<prepare/>
<urlParams/>
<position>60</position>
<liParams>
<class>top-register</class>
</liParams>
<aParams>
<class>top-register-a</class>
</aParams>
<beforeText />
<afterText />
</action>
</reference>
</customer_logged_out>
<customer_logged_in>
<!-- add Log Out (when customer is logged in) -->
<reference name="top.links">
<action method="addLink" translate="label title" module="customer">
<label>Log Out</label>
<url helper="customer/getLogoutUrl"/>
<title>Log Out</title>
<prepare/>
<urlParams/>
<position>70</position>
<liParams>
<class>top-log-out</class>
</liParams>
<aParams>
<class>top-log-out-a</class>
</aParams>
<beforeText />
<afterText />
</action>
</reference>
</customer_logged_in>
</layout>
@jasontipton
Copy link
Author

also change:
app/design/frontend/YOUR_PACKAGE/YOUR_THEME/template/page/template/links.phtml ~ line 40
from:
<ligetIsFirst()||$_link->getIsLast()): ?> class="getIsFirst()): ?>firstgetIsLast()): ?> last" getLiParams() ?>>getBeforeText() ?>
to:

  • getLiParams() ?>>getBeforeText() ?>

    This removes the 'first' and 'last' class Magento adds by default that blocks adding some classes

  • @jasontipton
    Copy link
    Author

    And in

    app/design/frontend/YOUR_PACKAGE/YOUR_THEME/template/page/template/linksblock.phtml ~line 32
    from:
    <ligetIsFirst()||$this->getIsLast()): ?> class="getIsFirst()): ?>firstgetIsLast()): ?> last" getLiParams() ?>>getBeforeText() ?>
    to:

  • getLiParams() ?>>getBeforeText() ?> This removes the 'first' and 'last' class Magento adds by default that blocks adding some classes
  • Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment