• I have styled my current_page_parent so that when you are on a child page the parent nav button is highlighted in the navbar.
    e.g. if Toast is a subpage (child) of Bread Products, then Bread Products is highlighted in the navbar.

    This is all good. The problem comes when I do a search. My search results page (search.php) triggers my Blog nav button to be highlighted. it’s as if it thinks that the search results page is a child page of the Blog.

    How can I stop it from doing this? I want my search results page to have no button highlighted in the navbar as it is a separate thing in my mind and does not belong in any of my sections.

    Can anyone help?

    thanks in advance

Viewing 6 replies - 1 through 6 (of 6 total)
  • Maybe if you posted some code they could ??

    It’s probably just a case of excluding it using an is_search()

    Regards
    Rich

    Thread Starter trixienolix

    (@trixienolix)

    hi, not sure what code is going to be useful really. Here’s my navigation… nothing unusual there:

    <ul>
          <?php wp_list_pages('title_li=&depth=1&sort_column=menu_order&exclude=57,59,61' ); ?>
    
    	</ul>

    Let me know what else is helpful and I’ll stick it up.

    I guess I’m just asking why search results think they are the child of the blog page.

    I had the same question – and was happy to see I was not the first. In my case, the problem was due to sloppy use of $post->post_parent. My sidebar.php uses the $post data to refer to the current post ID, title, etc., for static page formatting. However, and somewhat surprisingly, in a search page $post->* apparently refers to one of the search results, presumably the first or the last.

    In my situation, it was easy to use is_search() to exclude such cases. However, this won’t work for somebody using generic wp_list_pages() output. If somebody has time it would be good to figure out and document the semantics of $post->* on the search pages. I’m guessing that a search page should consider $post as null.

    I just had this problem. I tried setting $post to null for search pages – trying loads of different places to do it – to no avail. I settled on this filter hack in my theme’s functions.php:

    function noCurrentNavInSearch( $content ) {
    	if ( is_search() ) $content = preg_replace( '/ current_page[_a-z]*([\" ])/', '\1', $content );
    	return $content;
    }
    add_filter( 'wp_list_pages', 'noCurrentNavInSearch' );

    Sorry, when I suggested using $post as null during search, I meant this would have to be implemented in the bowels of the core code, not in anything we can touch safely.

    @gyrus Thanks for the function! It did the trick for me.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘current_page_parent for search results’ is closed to new replies.