WordPress.org

Ready to get started?Download WordPress

Forums

conditional statement navigation and unique id's (2 posts)

  1. zoblue
    Member
    Posted 6 years ago #

    Using these posts:
    Conditional Navigation Highlighting Problems
    http://wordpress.org/support/topic/162320?replies=2

    Style current Page differently for wp_list_pages?
    http://wordpress.org/support/topic/158749?replies=3

    Along with this codex page:
    Dynamic menu highlighting
    http://codex.wordpress.org/Dynamic_Menu_Highlighting

    I was able to edit some code to create my blog's navigation with unique css id's for each list item and have the css id change when you were on the corresponding page. I'm posting the code here in case it is useful to someone else:

    <ul id="nav">
    <li <?php if (is_home()) { echo "id=\"uhome\""; ?>><a href="<?php bloginfo('url') ?>/">home</a>
    <?php } else { echo "id=\"home\">";?><a href="<?php bloginfo('url') ?>/">home</a><?php }?></li>
    
    <li <?php if (is_page('archives') || is_single()) { echo "id=\"uarch\""; ?>>
    <a href="<?php bloginfo('url') ?>/archive">archives</a>
    <?php } else { echo "id=\"archive\">";?><a href="<?php bloginfo('url') ?>/archive">archives</a><?php } ?></li>
    
    <li <?php if (is_page('colophon')) { echo "id=\"uabt\""; ?>>
    <a href="<?php bloginfo('url') ?>/colophon">colophon</a>
    <?php } else { echo "id=\"about\">";  ?><a href="<?php bloginfo('url') ?>/colophon">colophon</a><?php } ?></li>
    
    <li <?php if (is_page('contact')) { echo "id=\"ucont\""; ?>>
    <a href="<?php bloginfo('url') ?>/contact">contact me</a>
    <?php } else { echo "id=\"contact\">";?><a href="<?php bloginfo('url') ?>/contact">contact me</a><?php } ?></li>
    </ul>

    I hope it helps someone in some way. :)

  2. Ivovic
    Member
    Posted 6 years ago #

    wow, a selfless act as the first post in a thread... unbelievable ;)

    thanks for your contribution :D

Topic Closed

This topic has been closed to new replies.

About this Topic