Magento Forum

   
“My Wishlist” CSS Class unassigned
 
Djidan
Jr. Member
 
Total Posts:  6
Joined:  2011-03-10
 

Hi guys,

I’ve been looking for hours for a way to add a CSS class to “My Wishlist” on Magento 1.5. I checked the source code and I was surprized to see that there was no class there (look at the code below)… I found this : http://www.magentocommerce.com/boards/viewthread/214259/ but that trick is not working here. Oh and I also tried to edit the wishlist block (links.php) in the core files… no luck.

Well as you have probably figured, I wanna add a background image/icon to “My Wishlist” via a class="top-link-wishlist”. I managed to do it for “Checkout” and “Cart” in the CSS file because… well… they had an assigned class ! So what do I have to do ? Any idea ?

Here’s my code :

{div class="quick-access"}
{p class="welcome-msg"}{/p}
{ul class="links"}
{li class="first" }{a href="http://www.rizlan.com/boutique/index.php/customer/account/" title="Mon compte” }Mon compte{/a}{/li}
{li ><a href="http://www.rizlan.com/boutique/index.php/wishlist/" title="Ma liste d’envies” >Ma liste d’envies{/a}{/li}
{li ><a href="http://www.rizlan.com/boutique/index.php/checkout/cart/" title="Mon panier” class="top-link-cart”>Mon panier{/a}{/li}
{li ><a href="http://www.rizlan.com/boutique/index.php/checkout/" title="Commander" class="top-link-checkout”>Commander{/a}{/li}
{li class=” last” ><a href="http://www.rizlan.com/boutique/index.php/customer/account/login/" title="Connexion" >Connexion{/a}{/li}
{/ul}
{/div}

Thanks.

 
Magento Community Magento Community
Magento Community
Magento Community
 
clorne
Sr. Member
 
Total Posts:  236
Joined:  2008-01-10
London
 

If you have been unable to change the xml file successfully you could try another method

go to

/app/design/frontend/default/{your theme}/template/page/template/links.phtml

look for

<?php elseif($_link->getIsLast()): ?> class="last"<?php endif; ?>

and change to

<?php elseif($_link->getIsLast()): ?> class="last" <?php elseif($_link->getTitle()=='My Wishlist'): ?> class="fred" <?php endif; ?>

 
Magento Community Magento Community
Magento Community
Magento Community
 
Jeyhun
Member
 
Total Posts:  38
Joined:  2010-02-20
 

Here’s the reason why class is missing in wishlist Mage v.1.5.0.1:

Class Mage_Wishlist_Block_Links in v 1.5.0.1

* @deprecated after 1.4.2.0
     
* @see Mage_Wishlist_Block_Links::__construct
     
*
     * @return array
     */
    public function 
addWishlistLink()
    
{
        
return $this;
    
}

Class Mage_Wishlist_Block_Links in v 1.4.1.1

/**
     * Add link on wishlist page in parent block
     *
     * @return Mage_Wishlist_Block_Links
     */
    public function addWishlistLink()
    
{
        $parentBlock 
$this->getParentBlock();
        if (
$parentBlock && $this->helper('wishlist')->isAllow()) {
            $count 
$this->helper('wishlist')->getItemCount();
            if (
$count 1{
                $text 
$this->__('My Wishlist (%d items)'$count);
            
}
            
else if ($count == 1{
                $text 
$this->__('My Wishlist (%d item)'$count);
            
}
            
else {
                $text 
$this->__('My Wishlist');
            
}
            $parentBlock
->addLink($text'wishlist'$texttrue, array(), 30null'class="top-link-wishlist"');
        
}
        
return $this;
    
}

 
Magento Community Magento Community
Magento Community
Magento Community
 
Djidan
Jr. Member
 
Total Posts:  6
Joined:  2011-03-10
 

Ok so does this mean that I have to copy/paste that “old” string of code between “public” and “return this” in 1.5 ?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Djidan
Jr. Member
 
Total Posts:  6
Joined:  2011-03-10
 

I tried both solutions but nothing new. I checked the source code and still the “class” is missing. Thanks for the help guys at least you tried something…

Someone know why they “unassigned” that class for this particular link ?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Jeyhun
Member
 
Total Posts:  38
Joined:  2010-02-20
 

Here’s something that works for me in v. 1.5.0.1:

Class Mage_Page_Block_Template_Links_Block (see /app/design/frontend/base/default/template/page/template)

Add the following:

<?php if($this->getTitle()==__('My Wishlist')): ?> class="top-link-wishlist"<?php endif; ?>

To change from this:

<li<?php if($this->getIsFirst()||$this->getIsLast()): ?> class="<?php if($this->getIsFirst()): ?>first<?php endif; ?><?php if($this->getIsLast()): ?> last<?php endif; ?>"<?php endif; ?> <?php echo $this->getLiParams() ?>><?php echo $this->getBeforeText() ?><a href="<?php echo $this->getLinkUrl() ?>" title="<?php echo $this->getTitle() ?>" <?php echo $this->getAParams() ?>><?php echo $this->getLabel() ?></a><?php echo $this->getAfterText() ?></li>

To this:

<li<?php if($this->getTitle()==__('My Wishlist')): ?> class="top-link-wishlist"<?php endif; ?><?php if($this->getIsFirst()||$this->getIsLast()): ?> class="<?php if($this->getIsFirst()): ?>first<?php endif; ?><?php if($this->getIsLast()): ?> last<?php endif; ?>"<?php endif; ?> <?php echo $this->getLiParams() ?>><?php echo $this->getBeforeText() ?><a href="<?php echo $this->getLinkUrl() ?>" title="<?php echo $this->getTitle() ?>" <?php echo $this->getAParams() ?>><?php echo $this->getLabel() ?></a><?php echo $this->getAfterText() ?></li>

NOTE !
It is encouraged to override the above-mentioned class instead of altering the core files like shown above.

Hope this works.

Please see an update in post #9

 
Magento Community Magento Community
Magento Community
Magento Community
 
Djidan
Jr. Member
 
Total Posts:  6
Joined:  2011-03-10
 

Dude! If you were a lady I would kiss you. Kidding. Your solution is working but I tweaked a little something in there.

Your code was :

<?php if($this->getTitle()==__('My Wishlist')): ?> class="top-link-wishlist"<?php endif; ?>
 
<li<?php if($this->getTitle()==__('My Wishlist')): ?> class="top-link-wishlist"<?php endif; ?><?php if($this->getIsFirst()||$this->getIsLast()): ?> class="<?php if($this->getIsFirst()): ?>first<?php endif; ?><?php if($this->getIsLast()): ?> last<?php endif; ?>"<?php endif; ?> <?php echo $this->getLiParams() ?>><?php echo $this->getBeforeText() ?><a href="<?php echo $this->getLinkUrl() ?>" title="<?php echo $this->getTitle() ?>" <?php echo $this->getAParams() ?>><?php echo $this->getLabel() ?></a><?php echo $this->getAfterText() ?></li>

The thing is that your first line wasn’t needed. It made appear a “class=top-link-wishlist” in text in the menu bar. So what I did is fairly simple. I kept the intro code and pasted the second part of your code and voila!

Here’s the code for you people that have the same problem (make sure you create a corresponding CSS class of course) :

<?php
/**
 * @see Mage_Page_Block_Template_Links_Block
 */
?>
<li<?php if($this->getTitle()==__('My Wishlist')): ?> class="top-link-wishlist"<?php endif; ?><?php if($this->getIsFirst()||$this->getIsLast()): ?> class="<?php if($this->getIsFirst()): ?>first<?php endif; ?><?php if($this->getIsLast()): ?> last<?php endif; ?>"<?php endif; ?> <?php echo $this->getLiParams() ?>><?php echo $this->getBeforeText() ?><a href="<?php echo $this->getLinkUrl() ?>" title="<?php echo $this->getTitle() ?>" <?php echo $this->getAParams() ?>><?php echo $this->getLabel() ?></a><?php echo $this->getAfterText() ?></li>

CSS class

.quick-access .links li.top-link-wishlist { backgroundurl(../images/icons/wishlist_ico.pngno-repeat left centerpadding-left20px;    }

P.S And as you said… I didn’t touch the “core” files. :)

 
Magento Community Magento Community
Magento Community
Magento Community
 
james1892
Jr. Member
 
Total Posts:  25
Joined:  2010-04-08
 

You guys have massively over complicated this you just need to change the method from addLinkBlock to addLInk as it is with all the other links. http://www.gentocom.co.uk/?p=65#wishlist

 
Magento Community Magento Community
Magento Community
Magento Community
 
Guillermo Gallo
Jr. Member
 
Total Posts:  16
Joined:  2010-06-08
 

Hi, that solution (http://www.gentocom.co.uk/?p=65#wishlist) has two problems though; The linkblock contains how many items you have on your list when you actually have items on your wishlist, with this code this is not shown. The link is also moved to the last item in the row.

Neither the above solutions worked in my theme, i’m running 1.5.0.1

Magento must fix this in 1.6!.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Jeyhun
Member
 
Total Posts:  38
Joined:  2010-02-20
 

Hi, all

I agree with james1892 (#7) that my original solution (#5) is not the best. Here’s a better solution:

1. /app/design/frontend/{...}/layout/wishlist.xml
In the node

<reference name="top.links">
change from
<action method="addLinkBlock"><blockName>wishlist_link</blockName></action>
to
<action method="addLink" translate="label title" module="wishlist" ifconfig="wishlist/general/active"><label>Wishlist</label><url helper="wishlist/getListUrl"/><title>My Wishlist</title><prepare/><urlParams/><liParams/><aParams>class="MY-CSS-CLASS"</aParams></action>

2. /skin/frontend/{...}/css/MYSTYLESCSS.css
Add/change

.MY-CSS-CLASS { backgroundurl(../images/{...}/MYWISHLIST_ICON.xxxno-repeat left center;    }

Hope this works well!

Reference: Adding Classing/Icons to top links.

 
Magento Community Magento Community
Magento Community
Magento Community
 
trang79
Jr. Member
 
Total Posts:  19
Joined:  2012-06-19
 

Hi Jeyhun
Your code don\’t working on magento 1.7.0.2
It just set class for <li> tag, not set for <a> tag.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top