www.webdeveloper.com
Results 1 to 2 of 2

Thread: PHP If Else with CSS Class.

  1. #1
    Join Date
    Jul 2010
    Posts
    6

    Unhappy 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 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.

  2. #2
    Join Date
    May 2014
    Posts
    618
    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.
    Java is to JavaScript as Ham is to Hamburger.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles