PHP If Else with CSS Class.
I have a dropdown menu with a main menu and a sub menu. The sub menus are only displayed if the css class="sub menu-item". However, when the css class is "sub menu-item", I do not want the href="whatever.html" in the A tag.
What I want to accomplish is this:
<li class="sub menu-item">(If li class="sub menu-item", display <a>Link Text</a> else display <a href="link.html">Link Text</a></li>
I am new to PHP and using this to be implemented with Wayfinder in MODX. Any help is greatly appreciated.
You are saying you know it has those classes, so why have the IF? Or are those classes coming from some sort of variable or OTHER If statement before you output it.
Not that there's usually a reason to have classes like 'sub' or 'menu-item' on a dropdown menu if you understand inheritance -- that's just code bloat in the markup. It's also bad practice to use a A without a href or name on it (the latter being a relic of nyetscape 4 style coding)... if it's not going to do what a anchor does, use a span... though not having anchors pointing at something as a menu item is usually a bad idea too just in case the menu doesn't work.
Really to answer properly we need to see a heck of a lot more of what's going on there; it could be the menu is being built wrong/bloated in the first place. (just from what I'm seeing!)
Last edited by deathshadow; 06-27-2014 at 11:57 PM.
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Tags for this Thread