I am trying to remove links on my account navigation. I looked at the customer/account/navigation.phtml template. The template grabs links by $this->getLinks(). How do I edit getLinks() method so that I can remove some of links?
问题:
回答1:
The answer to your question is ultimately, it depends. The links in that navigation are added via different layout XML files. Here's the code that first defines the block in layout/customer.xml
. Notice that it also defines some links to add to the menu:
<block type="customer/account_navigation" name="customer_account_navigation" before="-" template="customer/account/navigation.phtml">
<action method="addLink" translate="label" module="customer"><name>account</name><path>customer/account/</path><label>Account Dashboard</label></action>
<action method="addLink" translate="label" module="customer"><name>account_edit</name><path>customer/account/edit/</path><label>Account Information</label></action>
<action method="addLink" translate="label" module="customer"><name>address_book</name><path>customer/address/</path><label>Address Book</label></action>
</block>
Other menu items are defined in other layout files. For example, the Reviews module uses layout/review.xml
to define its layout, and contains the following:
<customer_account>
<!-- Mage_Review -->
<reference name="customer_account_navigation">
<action method="addLink" translate="label" module="review"><name>reviews</name><path>review/customer</path><label>My Product Reviews</label></action>
</reference>
</customer_account>
To remove this link, just comment out or remove the <action method=...>
tag and the menu item will disappear. If you want to find all menu items at once, use your favorite file search and find any instances of name="customer_account_navigation"
, which is the handle that Magento uses for that navigation block.
回答2:
If you want to selectively remove links without having to copy/edit entire xml files, a nice solution can be found in this post in the magento forums
In this solution, you override the Mage_Customer_Block_Account_Navigation
block with a local version, that adds a removeLinkByName
method, which you then use in your layout.xml
files, like so:
<?xml version="1.0"?>
<layout version="0.1.0">
<customer_account>
<reference name="customer_account_navigation" >
<!-- remove the link using your custom method -->
<action method="removeLinkByName">
<name>recurring_profiles</name>
</action>
<action method="removeLinkByName">
<name>billing_agreements</name>
</action>
</reference>
</customer_account>
</layout>
回答3:
The easiest way to remove any link from the My Account panel in Magento is to first copy:
app/design/frontend/base/default/template/customer/account/navigation.phtml
to
app/design/frontend/enterprise/YOURSITE/template/customer/account/navigation.phtml
Open the file and fine this line, it should be around line 34:
<?php $_index = 1; ?>
Right below it add this:
<?php $_count = count($_links); /* Add or Remove Account Left Navigation Links Here -*/
unset($_links['tags']); /* My Tags */
unset($_links['invitations']); /* My Invitations */
unset($_links['enterprise_customerbalance']); /* Store Credit */
unset($_links['OAuth Customer Tokens']); /* My Applications */
unset($_links['enterprise_reward']); /* Reward Points */
unset($_links['giftregistry']); /* Gift Registry */
unset($_links['downloadable_products']); /* My Downloadable Products */
unset($_links['recurring_profiles']); /* Recurring Profiles */
unset($_links['billing_agreements']); /* Billing Agreements */
unset($_links['enterprise_giftcardaccount']); /* Gift Card Link */
?>
Just remove any of the links here that you DO want to appear.
回答4:
You can also disable the menu items through the backend, without having to touch any code. Go into:
System > Configuration > Advanced
You'll be presented with a long list of options. Here are some of the key modules to set to 'Disabled' :
Mage_Downloadable -> My Downloadable Products
Mage_Newsletter -> My Newsletter
Mage_Review -> My Reviews
Mage_Tag -> My Tags
Mage_Wishlist -> My Wishlist
I also disabled Mage_Poll, as it has a tendency to show up in other page templates and can be annoying if you're not using it.
回答5:
Its work 100% i am Sure.
Step 1: Go To ( YourTemplate/customer/account/navigation.phtml )
Step 2: Replace This Line: <?php $_count = count($_links); ?>
With:
<?php $_count = count($_links); /* Add or Remove Account Left Navigation Links Here -*/
unset($_links['account']); /* Account Info */
unset($_links['account_edit']); /* Account Info */
unset($_links['tags']); /* My Tags */
unset($_links['invitations']); /* My Invitations */
unset($_links['reviews']); /* Reviews */
unset($_links['wishlist']); /* Wishlist */
unset($_links['newsletter']); /* Newsletter */
unset($_links['orders']); /* My Orders */
unset($_links['address_book']); /* Address */
unset($_links['enterprise_customerbalance']); /* Store Credit */
unset($_links['OAuth Customer Tokens']); /* My Applications */
unset($_links['enterprise_reward']); /* Reward Points */
unset($_links['giftregistry']); /* Gift Registry */
unset($_links['downloadable_products']); /* My Downloadable Products */
unset($_links['recurring_profiles']); /* Recurring Profiles */
unset($_links['billing_agreements']); /* Billing Agreements */
unset($_links['enterprise_giftcardaccount']); /* Gift Card Link */
?>
回答6:
Technically the answer of zlovelady is preferable, but as I had only to remove items from the navigation, the approach of unsetting the not-needed navigation items in the template was the fastest/easiest way for me:
Just duplicate
app/design/frontend/base/default/template/customer/account/navigation
to
app/design/frontend/YOUR_THEME/default/template/customer/account/navigation
and unset the unneeded navigation items before the get rendered, e.g.:
<?php $_links = $this->getLinks(); ?>
<?php
unset($_links['recurring_profiles']);
?>
回答7:
Also, you need to do something like this in config.xml if you are developing a customized module
<frontend>
<layout>
<updates>
<hpcustomer>
<file>hpcustomer.xml</file>
</hpcustomer>
</updates>
</layout>
</frontend>
回答8:
Open navigation.phtml
app/design/frontend/yourtheme/default/template/customer/account/navigation.phtml
replace
<?php $_links = $this->getLinks(); ?>
with unset link which you want to remove
<?php
$_count = count($_links);
unset($_links['account']); // Account Information
unset($_links['account_edit']); // Account Information
unset($_links['address_book']); // Address Book
unset($_links['orders']); // My Orders
unset($_links['billing_agreements']); // Billing Agreements
unset($_links['recurring_profiles']); // Recurring Profiles
unset($_links['reviews']); // My Product Reviews
unset($_links['wishlist']); // My Wishlist
unset($_links['OAuth Customer Tokens']); // My Applications
unset($_links['newsletter']); // Newsletter Subscriptions
unset($_links['downloadable_products']); // My Downloadable Products
unset($_links['tags']); // My Tags
unset($_links['invitations']); // My Invitations
unset($_links['enterprise_customerbalance']); // Store Credit
unset($_links['enterprise_reward']); // Reward Points
unset($_links['giftregistry']); // Gift Registry
unset($_links['enterprise_giftcardaccount']); // Gift Card Link
?>
回答9:
Most of the above work, but for me, this was the easiest.
Install the plugin, log out, log in, system, advanced, front end links manager, check and uncheck the options you want to show. It also works on any of the front end navigation's on your site.
http://www.magentocommerce.com/magento-connect/frontend-links-manager.html
回答10:
You can also use this free plug-and-play extension:
http://www.magentocommerce.com/magento-connect/manage-customer-account-menu.html
This extension does not touch any of the Magento core files.
With this extension you are able to:
- Decide per menu item to show or hide it with one click in the Magento backend.
- Rename menu items easily.
回答11:
My solution was to completely remove the block in local.xml and create it with the blocks I needed, so, for example
<customer_account>
<reference name="left">
<action method="unsetChild">
<name>customer_account_navigation</name>
</action>
<block type="customer/account_navigation" name="customer_account_navigation" before="-" template="customer/account/navigation.phtml">
<action method="addLink" translate="label" module="customer">
<name>account</name>
<path>customer/account/</path>
<label>Account Dashboard</label>
</action>
<action method="addLink" translate="label" module="customer">
<name>account_edit</name>
<path>customer/account/edit/</path>
<label>Account Information</label>
</action>
</block>
</reference>
</customer_account>