WordPress.org

Ready to get started?Download WordPress

Forums

current_page_parent, current_page_item but what about three-level menu ? (8 posts)

  1. dooshan
    Member
    Posted 6 years ago #

    When I'm on the sub-sub page only that menu item and the menu item above in the hiearchy are affected with the current_page styles, not the parent page. Example:

    Home
    Portfolio
    - Customers
    - - Company
    Contact

    when it should be

    Home
    Portfolio
    - Customers
    - - Company
    Contact

    Any idea how I could fix this?

  2. MichaelH
    Member
    Posted 6 years ago #

    I'll take a quick guess and say that might be already reported as an enhancement via Trac Ticket 4351.

    Let me know if I'm wrong about that.

  3. dooshan
    Member
    Posted 6 years ago #

    Thanks, I think that'll do the trick

  4. mgk
    Member
    Posted 6 years ago #

    I had to come up with something to do the same thing ... here's what I have at the moment;

    replace the following in classes.php (it's around line 515).

    /*
    $_current_page = get_page( $current_page );
    if ( $page->ID == $current_page )
    	$css_class .= ' current_page_item ';
    elseif ( $_current_page && $page->ID == $_current_page->post_parent )
    	$css_class .= ' current_page_parent';
    */
    $_parent = get_page($current_page)->post_parent;
    $_parentparent = get_page(get_page($current_page)->post_parent)->post_parent;
    if ( $page->ID == $current_page ) $css_class .= ' current_page_item';
    elseif ( $page->ID == $_parent ) $css_class .= ' current_page_parent';
    elseif ( $page->ID == $_parentparent ) $css_class .= ' current_page_parent_parent';

    I'd be very interested to see someone improve this - I don't really know PHP I just kind of guessed and tried things until got it working.

    Site is http://www.unofficialaleagueupdate.com.au/?page_id=45 - special editions is three levels deep but I want to keep it highlighted when you are in that section.

  5. iPaulPro
    Member
    Posted 6 years ago #

    Use the CSS selector

    current_page_ancestor

    eg:

    li.current_page_item, li.current_page_parent, li.current_page_ancestor {
    	font-weight: bold; }
  6. Dr C
    Member
    Posted 6 years ago #

    10 hours of work, several plugins later and I find that it all comes down to one little variable:

    current_page_ancestor

    Genius! Knowledge really is a powerful thing.

    So with that input my horizontal menu is finished http://www.colincaprani.com If it would help people I could blog about the solution?

  7. iPaulPro
    Member
    Posted 6 years ago #

    ::clears throat:: (echo)

  8. Dr C
    Member
    Posted 6 years ago #

    Hmmm.. sorry man - just saw this now. Don't know how I missed your post the first time!!

Topic Closed

This topic has been closed to new replies.

About this Topic