WordPress.org

Ready to get started?Download WordPress

Forums

Simple Portfolio
wp_nav_menu not setting "current" class (21 posts)

  1. Steven Vachon
    Member
    Posted 3 years ago #

    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.

  2. piffpaffpuff
    Member
    Posted 3 years ago #

    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;
    }
  3. Steven Vachon
    Member
    Posted 3 years ago #

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

  4. piffpaffpuff
    Member
    Posted 3 years ago #

    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);
  5. Steven Vachon
    Member
    Posted 3 years ago #

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

  6. ZoIcHi
    Member
    Posted 3 years ago #

    avete trovato una soluzione? ho lo stesso problema e non trovo soluzione ... :(

  7. ZoIcHi
    Member
    Posted 3 years ago #

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

  8. luispic
    Member
    Posted 3 years ago #

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

  9. luispic
    Member
    Posted 3 years ago #

    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

  10. luispic
    Member
    Posted 3 years ago #

    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*...

  11. Steven Vachon
    Member
    Posted 3 years ago #

    This bug still exists in v1.8

  12. grandmagustfront
    Member
    Posted 2 years ago #

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

    Thanks

  13. luispic
    Member
    Posted 2 years ago #

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

    :cheers:

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

  14. grandmagustfront
    Member
    Posted 2 years ago #

    Hey luispic,

    I never even seen your post LOL

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

    Thanks!!

  15. grandmagustfront
    Member
    Posted 2 years ago #

    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;
    }
  16. luispic
    Member
    Posted 2 years ago #

    @tylercollins1986
    Glad to hear that it did work ;)

  17. Steven Vachon
    Member
    Posted 2 years ago #

    Thanks for the fix. However, this is something that should have been fixed in the plugin long ago. Having us use a messy workaround like this is a testament to the lack of dedication from the original developer.

  18. luispic
    Member
    Posted 2 years ago #

    You're probably right Steven, but you have to keep in mind that the plugin is free after all, and I can personally say that I lack the ability to develop a plugin like this (or to fix it since it's open source), so the mere fact that the developer cares enough to share something I can use, and is as good as it is is very appreciated.

  19. Steven Vachon
    Member
    Posted 2 years ago #

    I have released plugins; just click my name on the left. If someone finds a serious bug, I fix it. Sometimes it takes a little while, but it gets done. This plugin has seen a few revisions over the course of this, now, 5 month old bug, and for that there is no excuse.

  20. Themella
    Member
    Posted 2 years ago #

    @luispic can you tell mi something about your solution? I can't link categories in my porfolio.
    link lead me to undefined page.

  21. luispic
    Member
    Posted 2 years ago #

    @themella sure, what do you need to know?

    if the link leads to a undefined page, you might be defining it wrong. do you have a link?

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic