Forums

current_page_item primary and sub navigation "Dynamic" onstates (3 posts)

  1. karonos
    Member
    Posted 1 year ago #

    Searched and searched but could find nothing. Let me explain the situation.

    the class "current_page_item" gives an on-state to the current link your on within the navigation.

    EX: if you click the "home" Tab on a site and it changes a different color (and stays that color while on this page), This is considered an on-state.

    By default, WordPress can do this in the 'Primary Navigation" using the classes.php file with the following code:

    extract($args, EXTR_SKIP);
    		$css_class = array('page_item', 'page-item-'.$page->ID);
    		if ( !empty($current_page) ) {
    			$_current_page = get_page( $current_page );
    			if ( isset($_current_page->ancestors) && in_array($page->ID, (array) $_current_page->ancestors) )
    				$css_class[] = 'current_page_ancestor';
    			if ( $page->ID == $current_page )
    				$css_class[] = 'current_page_item';
    			elseif ( $_current_page && $page->ID == $_current_page->post_parent )
    				$css_class[] = 'current_page_parent';
    		} elseif ( $page->ID == get_option('page_for_posts') ) {
    			$css_class[] = 'current_page_parent';
    		}

    However, I have a sub navigation below the Primary navigation. So when you click in the primary navigation a sub navigation displays below it. BUT, if I then click a link in the sub navigation the on-state in the primary navigation goes away and the on-state now displays in the sub navigation. Which is fine, except that I want the Primary Navigation to have the on-state along side with the sub navigation.

    The solution I seek will require editing of the code above, but I'm not sure how to do so. I need the code to say, "If the page is a current page, use the css code current_page_item--AND If the current page has a parent page then also give it the css code current_page_item" Seeing that the sub navigation is the child of the Parent Primary Navigation. The child to parent is the only way I can think of targeting both menus for the on state.

    Note: My menus are not hard coded into templates using li tags... (other wise i could just use css to edit the onstate...) I'm using PHP to call the menus created with in the WordPress Dashboard. Hence needing the above code being updated. Unless you know a better Dynamic way?

  2. alchymyth
    The Sweeper
    Posted 1 year ago #

    try and style .current_page_parent the same as .current_page_item

  3. karonos
    Member
    Posted 1 year ago #

    Actually you change the .current-page-ancestor class... but if it wasn't for you, i wouldn't of figured this out.

    Thank you so much!!!!!!!!

Topic Closed

This topic has been closed to new replies.

About this Topic