WordPress.org

Forums

[resolved] Styling current_page_item in menu doesn't work (5 posts)

  1. xith
    Member
    Posted 6 years ago #

    Having some trouble with my menu--any help much appreciated!

    My sidebar div consists of

    <ul>
     <?php wp_page_menu('show_home=1&amp;sort_column=menu_order'); ?>
    </ul>

    In a view source, this shows up as

    <ul>
    <li ><a href="http://www.ipolari.com">Home</a></li>
    <li class="page_item page-item-4"><a href="http://www.ipolari.com/contact" title="Contact">Contact</a></li>
    <li class="page_item page-item-68 current_page_item"><a href="http://www.ipolari.com/titles" title="Titles">Titles</a></li>

    Etc., including more links.

    Two questions:
    1. I've been attempting to style the class "current_page_item" to change the color of the current page, but every way I've gone about trying to do it, nothing happens at all. The only color comes from #menu a:link, #menu a:visited in the css.

    2. The WP code for the menu ads these classes to the pages, but not to the link to the home page, so even if I get the style to work, it won't affect the home page. Any way to change this?

    Thanks!

  2. lhoylhoy
    Member
    Posted 6 years ago #

    hey i've never tried that code before but i'm using other code givr it a try it's much easier:

    <ul>
    <li<?php if (is_home()){echo " class=\"current_page_item\"";}?>><a href="<?php bloginfo('url') ?>" title="Home">Home</a></li>
    <?php wp_list_pages('title_li='); ?>
    </ul>

    then just style your .current_page_item

    hope this helps

  3. xith
    Member
    Posted 6 years ago #

    Thanks. I tried that out and it works for displaying the list, but styling .current_page_item still isn't doing anything. I'm not sure if I'm encountering a problem with WP coding or just messed something up in my style sheet (I'm more familiar with CSS than with WP, but by no means an expert).

  4. lhoylhoy
    Member
    Posted 6 years ago #

    definitely its the css,

    #menu ul li.current_page_item a

    your structure should look something like the above. Notice that li is attached to .current_page_item

  5. xith
    Member
    Posted 6 years ago #

    That was it. Thanks so much! I'll remember that for next time.

Topic Closed

This topic has been closed to new replies.

About this Topic