WordPress.org

Ready to get started?Download WordPress

Forums

Need help regarding PHP code - "selected" for multiple pages. (2 posts)

  1. APaige
    Member
    Posted 9 years ago #

    Hi there,

    On header.php one link's coding is:

    <li<?php if (is_page()) echo " class=\"selected\""; ?>>Speeches

    This is my problem. Currently all page links in the top navigation are "selected" because is_page(). If it's is_page(298) then only the Speeches link will highlight when on the Speeches page.

    But, I want it to highlight on the speeches page as well as pages under the speeches page. How do I do this?

    I could do:

    <li<?php if (is_page(298)) echo " class=\"selected\""; if (is_page(299)) echo " class=\"selected\""; ?>>Speeches

    and continue like that, although there would be loads of "if (is_page(###)) echo " class=\"selected\"";" - Is it possible to choose that it is "selected" when on certain pages?

    If so, how would I do this?

    Thanks :)

  2. Jonathan Dingman
    Member
    Posted 9 years ago #

    You could try something along the lines of http://us2.php.net/else or using an elseif if you have many pages you want to do this with. But if and else are going to be your friend with this.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.