Magento Forum

   
The class of first and last link in toplink
 
Black Cat
Mentor
 
Avatar
Total Posts:  3456
Joined:  2008-02-14
Assemini / Cagliari (Italy)
 

Hi
I would like to do so that All the links in the toplinks they had the class.
<? php echo $_link->getAParams ()?>
The code php that the class recalls php is this, but as I can do so that the classes appears for also the first one and the last link?

 
Magento Community Magento Community
Magento Community
Magento Community
 
ecommerce-store
Sr. Member
 
Avatar
Total Posts:  181
Joined:  2008-04-16
Roma
 

Yes, i would know mee too !!!

 
Magento Community Magento Community
Magento Community
Magento Community
 
ikuzyk
Magento Team
 
Avatar
Total Posts:  60
Joined:  2007-08-09
Ternopil, Ukraine
 

Try this:

<? php echo $_link->getIsFirst() ?>

or

<? php echo $_link->getIsLast() ?>

 
Magento Community Magento Community
Magento Community
Magento Community
 
Dale Grim
Jr. Member
 
Avatar
Total Posts:  14
Joined:  2008-05-14
 

If I understand the question you’re asking, you want all of the top links to have a class associated with them, not just the first and last ones, right?

In app/design/frontend/default/default/template/page/template/ there is a file called links.phtml.  You can copy this file into app/design/frontend/<your interface>/<your theme>/template/page/template or app/design/frontend/default/<your theme>/page/template - depending on how your customizations are setup.

From there, you’ll see a line that looks like this (ignore the word wrapping.  The line in the file is all on one line):

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

Assuming you want to add a class called “myNewClass” to all of the links, I think you want to change it to look like this:

<li <?php if($_link->getIsFirst()): ?> class="first myNewClass”<?php elseif($_link->getIsLast()): ?> class="last myNewClass<?php else : ?> class="myNewClass”<?php endif; ?><?php echo $_link->getLiParams() ?>><?php echo $_link->getBeforeText() ?><a href="<?php echo $_link->getUrl() ?>” title="<?php echo $_link->getTitle() ?>” <?php echo $_link->getAParams() ?>><?php echo $_link->getLabel() ?><?php echo $_link->getAfterText() ?></a></li>

Of course, take all of this with a grain of salt.  I’ve been playing with Magento for only 2 days.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Black Cat
Mentor
 
Avatar
Total Posts:  3456
Joined:  2008-02-14
Assemini / Cagliari (Italy)
 

I have not made sense of well.
Then I have this case:

It serves me also assign a class to the first one and the last link. Not a link defined for position, but for his functionality (for example the link of the “cart” it is “top-link-cart"). The first one and the last link don’t have the precise class.
How can you/ be added?
The option that you say you adds him/it to the <li> not to the link and however if the links changed disposition or if it removed someone of it, the class it would go to a different link.

 
Magento Community Magento Community
Magento Community
Magento Community
 
ecommerce-store
Sr. Member
 
Avatar
Total Posts:  181
Joined:  2008-04-16
Roma
 

I would know the same information ask by black cat

 
Magento Community Magento Community
Magento Community
Magento Community
 
ecommerce-store
Sr. Member
 
Avatar
Total Posts:  181
Joined:  2008-04-16
Roma
 

No one know??????????????????

 
Magento Community Magento Community
Magento Community
Magento Community
 
adimagento
Administrator
 
Avatar
Total Posts:  626
Joined:  2007-08-29
Los Angeles, CA
 

@Blackcat, can you please try to explain your question once again. It is a bit confusing.

 
Magento Community Magento Community
Magento Community
Magento Community
 
ecommerce-store
Sr. Member
 
Avatar
Total Posts:  181
Joined:  2008-04-16
Roma
 

@adimagento

Yo uare wonderfoul, who can concentrate on the question when you are that kind of avatar.....

Aahahah. i’m joking…

 
Magento Community Magento Community
Magento Community
Magento Community
 
Black Cat
Mentor
 
Avatar
Total Posts:  3456
Joined:  2008-02-14
Assemini / Cagliari (Italy)
 

I would like that there were also the css class for the first one and last link of the toplinks:
example:
class = “top-link-login”
class = “top-link-account”

 
Magento Community Magento Community
Magento Community
Magento Community
 
ecommerce-store
Sr. Member
 
Avatar
Total Posts:  181
Joined:  2008-04-16
Roma
 

I think that Black Cat want to know if is possibile to have a class for the first and the last link on the top link bar. He tell that the <li> who contain the links have the class but like .last e .first. He would apply a different background for every link.

Interest me too this tricks.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Magento
Magento Team
 
Avatar
Total Posts:  20
Joined:  2007-07-05
Los Angeles, CA
 

In this file - /app/design/frontend/default/default/layout/customer.xml you can find these lines:

<default>

        <!-- 
Mage_Customer -->
        <
reference name="top.links">
            <
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></action>
        </
reference>
    </default>

to assign a class you will need to change it to this:

<default>

        <!-- 
Mage_Customer -->
        <
reference name="top.links">
            <
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><li/><a>class="your-classname"</a></action>
        </
reference>
    </default>

The same with the “Log In” and “Log Out” link

hope its helps.

 
Magento Community Magento Community
Magento Community
Magento Community
 
ecommerce-store
Sr. Member
 
Avatar
Total Posts:  181
Joined:  2008-04-16
Roma
 

Thanks so much magento core. I go immediatly to test it.

Bye

 
Magento Community Magento Community
Magento Community
Magento Community
 
Black Cat
Mentor
 
Avatar
Total Posts:  3456
Joined:  2008-02-14
Assemini / Cagliari (Italy)
 
Magento Core - 19 May 2008 09:44 AM

In this file - /app/design/frontend/default/default/layout/customer.xml you can find these lines:

<default>

        <!-- 
Mage_Customer -->
        <
reference name="top.links">
            <
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></action>
        </
reference>
    </default>

to assign a class you will need to change it to this:

<default>

        <!-- 
Mage_Customer -->
        <
reference name="top.links">
            <
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><li/><a>class="your-classname"</a></action>
        </
reference>
    </default>

The same with the “Log In” and “Log Out” link

hope its helps.

If I insert the lace with </ li>, magento returns me an error.
If I make the changes instead without </ li>, the class is added to the <li> container of the link not to the tag <a>.
Moreover a class exists for already that tags and therefore there is an error in the code as specified two class that is:

<li class="first"class="top-link-account”><a href="http://127.0.0.1/magento/customer/account/" title="My Account” >My Account</a></li>

 
Magento Community Magento Community
Magento Community
Magento Community
 
laurent
Member
 
Total Posts:  75
Joined:  2007-08-31
Paris, France
 
Black Cat - 19 May 2008 03:07 PM

If I insert the lace with </ li>, magento returns me an error.

It’s not </li>, it’s

<li/>
. But in fact, you can use the words you want as long as the order is respected:
<liParams/><aParams>class="my_class"</aParams>

 
Magento Community Magento Community
Magento Community
Magento Community
 
Black Cat
Mentor
 
Avatar
Total Posts:  3456
Joined:  2008-02-14
Assemini / Cagliari (Italy)
 

it work!!!!!
Thanks Laurent!

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