WordPress.org

Ready to get started?Download WordPress

Forums

Keeping track of current and before-current list item (1 post)

  1. paperdoll
    Member
    Posted 8 years ago #

    I really need help with implementing a feature in my menu.

    The menu is build with an unordered list. I want two things to happen with my menu when you click on an item:

    1. The selected item should get the class "current"
    2. The item before it in the list should get the class "before-current"

    I know how to set the "current" id for the selected item using php. I do it like this:

    <ul id="menu">
    <li<?php if ($thisPage=="Page1")
    echo " class=\"current\""; ?>><span>Page1</span>

    <li<?php if ($thisPage=="Page2")
    echo " class=\"current\""; ?>><span>Page2</span>

    <li<?php if ($thisPage=="Page3")
    echo " class=\"current\""; ?>><span>Page3</span>

    What I don't know is how to set the "before-current" class to the item before it.

    Can someone help me with the php code for this? The code for: "If thisPage=="Page2" then set "Page2" to "current" and set "Page1" to "before-current".

    Anyone? Thank you very much.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags