/    Sign up×
Community /Pin to ProfileBookmark

PHP If Else with CSS Class.

Hi there, ?
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 [B]do not[/B] 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.?

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@deathshadowJun 28.2014 — 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!)
×

Success!

Help @ttzary spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.15,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...