Forums

Menu problem CSS choosing wrong current_page_parent (9 posts)

  1. TomCraig
    Member
    Posted 1 year ago #

    I'm using custom post types, but when selecting a custom post entry, my menu bar thinks I'm back in the "news" area of the site.

    For example, when I'm on the landing page for the area in question, I get: http://www.evoenergy.co.uk/case-studies/ (with case studies selected as current page).

    However, when I dig a bit deeper into the area, going to http://www.evoenergy.co.uk/system-type/on-roof/ for example, it highlights news, making me think I'm in the news area.

    I'm pretty sure this is CSS related: when I'm in the "case study" area, the css says this for the news menu item: menu-item menu-item-type-post_type current_page_parent menu-item-2883

    Any help MUCH appreciated!

  2. Linosa
    Member
    Posted 1 year ago #

    No, I don't think this is a css problem. You've written your css correct. The problem is that wordpress spots out wrong class as the current.

    Are this pages or categories?

  3. Linosa
    Member
    Posted 1 year ago #

    The problem is when you go to a single post, am I right?
    You've probably choosed news as the single-post-page.

  4. TomCraig
    Member
    Posted 1 year ago #

    Linosa

    Thanks for the fast response!

    It happens when I go to a category page: http://www.evoenergy.co.uk/system-type/on-roof/

    Or a single post page:
    http://www.evoenergy.co.uk/solar-pv-case-studies/20-x-solar-century-185-panels-in-gwent/

    The problem is I also have a news area, which needs to be set as news for single posts.

    Is there a way to tell wordpress that these custom posts are "special" and should be treated differently to standard news posts?

    Many Thanks

    Tom

  5. Linosa
    Member
    Posted 1 year ago #

    Yeah, I have the same problem myself. WordPress dosen't understand by defaut which page it's suppose to be.

    I solved it by putting a class around my different single-pages and then used it for marking the menu. Like:
    .interviews #menu ul li.menu-item-642 {background:#4e4e4e;}

    Guess there's better way of doing it though. I just could't come up with anything else.

  6. TomCraig
    Member
    Posted 1 year ago #

    is that along the lines of:

    // Add current-menu-item functionality to custom post types
    add_filter( 'hybrid_body_class', 'add_to_body_class' );
    
    function add_to_body_class( $class ) {
    
        global $post;
    
     	// Use switch to filter through custom post types
    	switch(get_post_type())
     	{
     		case 'Films':
    		// If custom post type is films, add current-menu-item class to body.
     		$classes[] = 'current-menu-item';
    
     		break;
    
     	}
     	// return the $classes array
     	return $classes;
    }

    it's pretty annoying that it doesn't see a custom post correctly...

  7. Linosa
    Member
    Posted 1 year ago #

    Where did you find that?

  8. TomCraig
    Member
    Posted 1 year ago #

  9. Linosa
    Member
    Posted 1 year ago #

    Ok, that script is suppose to give the body tag an class.. am I right or wrong?

Topic Closed

This topic has been closed to new replies.

About this Topic