• I’m currently about to wrap up a site and I’ve got it where using PHP code in my anchor tags, I’m able to get the rollover style to appear for my main links. Here’s an example:

    http://www.radioactivemedia.net/about/

    Pretty simple. The About button has a red background and an indicator instead of a gray background.

    Now clicking on any of the links in that page takes you to a child of the About main page but the About button’s background is grey again because the script doesn’t know what to do with child pages. Only the parent pages.

    Here’s the script I’m using:

    <?php if ( is_page('about')) { echo ' class="current_page_item"'; } ?> href="http://www.yoursite.com/parent/" title="Parent Page">Parent Page</a>

    I tried changing the is_page(‘parent’) with is_page(‘parent/child’) but that doesn’t seem to work. Any way it can work or just a FOL?

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter databell96

    (@databell96)

    Code didn’t show up right in the previous page. Let’s try it again:

    <a> href="http://www.radioactivemedia.net/about/" title="About">About</a>
    Thread Starter databell96

    (@databell96)

    Nope. No better. One more shot:

    <a <?php if ( is_page('about')) { echo ' class="current_page_item"'; } ?> href="http://www.radioactivemedia.net/about/" title="About">About</a>

    you could try to use

    is_page(array(42,’about-me’,’About Me And Joe’))
    Returns true when the Pages displayed is either post ID 42, or post_name “about-me”, or post_title “About Me And Joe”

    might work, if you know all the child pages, although it is not very dynamic.

    http://codex.wordpress.org/Conditional_Tags#A_PAGE_Page

    Thread Starter databell96

    (@databell96)

    Unfortunately, I got this error when I tried that:

    Parse error: syntax error, unexpected ‘{‘ in /home/radioa9/public_html/wp-content/plugins/exec-php/includes/runtime.php(42) : eval()’d code on line 2

    double check the code you entered:
    if you used the suggestion from the codex, you might have miscalculated the neccessary brackets; together with the if statement, it should look similar to: (three closing brackets before the { )

    <a <?php if ( is_page(array('about','below-about','about-child'))
     ) { echo ' class="current_page_item"'; } ?> href="http://www.radioactivemedia.net/about/" title="About">About</a>

    (obviously your stuff in the array would be different)

    Thread Starter databell96

    (@databell96)

    Alchymyth, I tried that on a page that should target:
    http://www.radioactivemedia.net/about/steve-pollak

    So I assume the array would be ‘about’,’steve-pollak’

    And my code looked like this:

    <a <?php if ( is_page(array('about','steve-pollak'))) { echo ' class="current_page_item"'; } ?> title="Steve Pollak" href="http://www.radioactivemedia.net/about/steve-pollak" target="_self">Steve Pollak, Media Strategist</a>

    Published it, went to the page, and still not seeing the hover graphic for About there. If you go to http://www.radioactivemedia.net/about/ you’ll see what it should look like.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘PHP: Allowing rollover style for a button to appear on certain pages’ is closed to new replies.