• I have the portfolio slug set to the same as one of my static pages. But, when I click the link in my top menu, it never actually goes to that page; instead does some kind of custom query.

    As a result of this, wp_nav_menu() never applies a “current” class to the
    <li> and instead, my “blog” (static page for posts) is set as “current”. This breaks my design.

Viewing 15 replies - 1 through 15 (of 20 total)
  • i’ve got the same problem. in your theme add the following code to your functions.php file. don’t forget to replace ##page_name## with the name/slug of the page you are displaying the portfolio:

    /**
     * Display the the correct page as selected when the post type is portfolio
     */
    function fn_page_css_class($css_class, $page)
    {
        if (get_post_type() == 'portfolio' || is_page('##page_name##'))
        {
            if ($page->ID == get_option('page_for_posts'))
            {
                foreach ($css_class as $key => $value)
                {
                    if ($value == 'current_page_parent')
                    {
                    	unset($css_class[$key]);
                    }
                }
            }
    
            if ($page->post_name == '##page_name##') {
                $css_class[] = 'current_page_parent';
            }
        }
    
        return $css_class;
    }
    Thread Starter Steven Vachon

    (@prometh)

    Hmm, is this supposed to be ran as a callback for a filter? ‘Cuz on its own it appears to do nothing.

    you’re right, sorry i forgot to copy/paste that portion. here again the whole code:

    /**
     * Display the the correct page as selected when the post type is portfolio
     */
    function fn_page_css_class($css_class, $page)
    {
        if (get_post_type() == 'portfolio' || is_page('##page_name##'))
        {
            if ($page->ID == get_option('page_for_posts'))
            {
                foreach ($css_class as $key => $value)
                {
                    if ($value == 'current_page_parent')
                    {
                    	unset($css_class[$key]);
                    }
                }
            }
    
            if ($page->post_name == '##page_name##') {
                $css_class[] = 'current_page_parent';
            }
        }
    
        return $css_class;
    }
    
    add_filter('page_css_class','fn_page_css_class', 10, 2);
    Thread Starter Steven Vachon

    (@prometh)

    Thanks, but this doesn’t seem to work with the ‘nav_menu_css_class’ filter hook.

    avete trovato una soluzione? ho lo stesso problema e non trovo soluzione … ??

    have found a solution? I have the same problem and I can not find solution

    I have the same problem here, anyone found a solution?

    Hi everyone, I found a nice simple solution, although I agree it isn’t the “more eficient one”

    First I’ve modified the header.php to include a css file to load once detected on the portfolio page:

    <?php if ( 'portfolio' == get_post_type() ) { ?>
    	<link rel="stylesheet" type="text/css" media="all" href="<?php bloginfo('template_url'); ?>/css/portfolio.css" />
    <?php } ?>

    Second I added this to my portfolio.css file:

    #menu-item-47{
    	font-weight: bold;
    }

    I got the #menu-item-47 id using firebug so it will work only on my website, but be sure to change it to what ever ID your website has, and it will from that you can apply whatever style you want on your portfolio page.

    If anyone has a nicer solution it’s very welcome I know my solution isn’t as fancy but you don’t have to modify any source code, wordpress’ nor the plugin’s.

    :cheers: all the way down from Guatemala

    Can you people believe that this doesn’t work on my live site?! grrrr! the function
    get_post_type()

    isn’t returning any value on my live site!!

    *I better laugh now*…

    Thread Starter Steven Vachon

    (@prometh)

    This bug still exists in v1.8

    I’m having the exact same problem as well! Has anyone came up with a solution yet?

    Thanks

    Have you read my solution? Mine is working, check it out: https://www.estudioink.com/portafolio

    :cheers:

    PS. I talked to the developer and he’s planning on releasing a v2.0 where this will work.

    Hey luispic,

    I never even seen your post LOL

    I will give it a try and come back if it works.

    Thanks!!

    Brilliant luispic! Works like a charm ??

    And for anyone else, this is the css I used for mine.

    li.page-item-928 a			{
        background-color: #00A0E4;
        color: #FFFFFF!important;
    }
    #menu li.current_page_parent a {
        background: #ddf1f2!important;
        color: #00a0e4!important;
    }

    @tylercollins1986
    Glad to hear that it did work ??

Viewing 15 replies - 1 through 15 (of 20 total)
  • The topic ‘[Plugin: Simple Portfolio] wp_nav_menu not setting "current" class’ is closed to new replies.