WordPress.org

Forums

[resolved] include multiple Pages? (4 posts)

  1. Doodlebee
    Member
    Posted 8 years ago #

    I'm full of questions today.

    Okay, I have a navigational list that is to go in the sidebar (using WordPress as a CMS, and all pages are Pages, save the index - that one will contain posts). This is a very complex sidebar, so I can't reall yuse the wp_list_pages() thing, as it messes up my classes and ID's. So I had to go for the straight hard-coding.

    I still need some dynamic activity though - namely for the hover state of the link to remain when it's aon the current Page. I have that working, no problem. My problem is that when I'm on a sub-Page (child of a Page), the sub_page link is highlighted as "current", but the parent is not. I would like for *both* the parent *and* the child to be highlighted - but I can't seem to find the proper code for that. I can *exclude* all I'd like - but it seems it would be easier if there were an "include" instead.

    This is my example so far:

    <ul id="nav">
    <li id="about" <?php if (is_page('2')) { echo "class=\"current\"";} ?>><a href="">
    <img src="<?php bloginfo('template_directory'); ?>/images/about_us_off.gif" width="128" height="16" alt="About Us" /></a></li>
    <ul id="subnav">
    <li id="about_lynne" <?php if (is_page('15')) { echo "class=\"current\"";} ?>><a href="">
    <img src="<?php bloginfo('template_directory'); ?>/images/about_lynne_off.gif" width="120" height="13" alt="About Lynne" /></a></li>
    <li id="about_book" <?php if (is_page('16')) { echo "class=\"current\"";} ?>><a href="">
    <img src="<?php bloginfo('template_directory'); ?>/images/about_book_off.gif" width="120" height="13" alt="About the Book" /></a></li>
    <li id="mission_values" <?php if (is_page('17')) { echo "class=\"current\"";} ?>><a href="">
    <img src="<?php bloginfo('template_directory'); ?>/images/mission_values_off.gif" width="120" height="13" alt="Mission &amp; Values" /></a></li>
    </ul>

    So, basically, if you're on Page 15 (which is "About Lynne", I would like "About Lynne" to be highlighted (as it is now), but I'd also like "About Us" to be highlighted as well (Page 2). I've tried:

    <li id="about" <?php if (is_page('2,15,16,17')) { echo "class=\"current\"";} ?>><a href="">
    <img src="<?php bloginfo('template_directory'); ?>/images/about_us_off.gif" width="128" height="16" alt="About Us" /></a></li>

    And it doesn't work *at all*. Would anyone know the correct formatting of that so I could get what I want? I'd appreciate it :)

  2. Chris_K
    Member
    Posted 8 years ago #

    Well, when I'm stumped I cheat and go lift some code from a working theme. ;-)

    As I recall, the current version of wp-andreas09 may do what you're looking for.

  3. Doodlebee
    Member
    Posted 8 years ago #

    Thanks Han - but nope. I downloaded it (I also have andreas07) and neither one did this.

    However, I figured it out on my own. Unreal.

    So, for future reference, if anyone needs this function, it's actually pretty easy. I'll use the above example, and this is what the end result should look like:

    <ul id="nav">
    <li id="about" <?php if (is_page('2') || is_page('15') || is_page('16') || is_page('17')) { echo "class="current"";} ?>><a href="">
    <img src="<?php bloginfo('template_directory'); ?>/images/about_us_off.gif" width="128" height="16" alt="About Us" /></a>
    <?php if (is_page('2') || is_page('15') || is_page('16') || is_page('17')) { ?>
    </li>
    <ul id="subnav">
    <li id="about_lynne" <?php if (is_page('15')) { echo "class="current"";} ?>><a href="">
    <img src="<?php bloginfo('template_directory'); ?>/images/about_lynne_off.gif" width="120" height="13" alt="About Lynne" /></a></li>
    <li id="about_book" <?php if (is_page('16')) { echo "class="current"";} ?>><a href="">
    <img src="<?php bloginfo('template_directory'); ?>/images/about_book_off.gif" width="120" height="13" alt="About the Book" /></a></li>
    <li id="mission_values" <?php if (is_page('17')) { echo "class="current"";} ?>><a href="">
    <img src="<?php bloginfo('template_directory'); ?>/images/mission_values_off.gif" width="120" height="13" alt="Mission &amp; Values" /></a></li>
    </ul>
    <?php } else { echo "</li>"; } ?>

    Woo-hoo! Yay for me :)

    Thanks, though!

  4. Copernicus
    Member
    Posted 8 years ago #

    THANK YOU! Your figuring this out (and posting the solution) has helped me as well! THANK YOU! THANK YOU! THANK YOU!

Topic Closed

This topic has been closed to new replies.

About this Topic