WordPress.org

Support

Support » Themes and Templates » [Resolved] Menus not displaying on archive pages

[Resolved] Menus not displaying on archive pages

  • Hi, this is the first problem I have countered that I haven’t been able to solve by searching this forum before. I have found a thread with the same problem

    http://wordpress.org/support/topic/wp-nav-menu-dissapears-in-category-pages-1?replies=21

    but the solution just lists all the posts from the primary menu only, without any styling.

    *INFO*

    I am currently working on a large project, built on _s as a foundation. The website I’m creating uses multiple menus that are registered in functions.php file.

    *PROBLEM*

    All the menus are working fine on all the pages EXCEPT the archive page.

    I have a page template which displays all the posts in their separate categories, on this page, the menus showing and working as desired, however on a category archive page, such as the Entertainment category, all the menus disappear.

    At the moment I am currently using:

    <?php wp_nav_menu( array( 'theme_location' => 'Menu Name' ) ); ?>

    To display my menus. When I use:

    <?php wp_nav_menu( array( 'menu' => 'Menu Name' ) ); ?>

    The menus appear but list all pages, instead of the chosen pages.

    I am stumped, and I can’t think of nor find a solution, and any help would be much, much appreciated.

    Thanks,
    Adam

Viewing 14 replies - 1 through 14 (of 14 total)
  • esmi

    @esmi

    Forum Moderator

    What theme are you using? Where did you download it from? Did you create the template for the category archive page? If so, is it a custom page template?

    Fixed using:

    <?php 
    
    $backup_query = $wp_query;
    $wp_query = new WP_Query(array('post_type' => 'post'));
    
    wp_nav_menu( array( 'theme_location' => 'guides' ) ); 
    
    $wp_query = $backup_query;
    
    ?>

    Seems a bit hacky, and I am not sure what it is doing, or why it works.

    Can anyone explain why this is happens? Or if there is a solution by removing the problem that causes it to disappear initially?

    esmi

    @esmi

    Forum Moderator

    Thanks for replying esmi.

    I was using underscores (_s), downloaded from:

    Home

    The posts were displayed on a page called articles which was using a page template. The archive was a slightly edited version of the themes archive.php, but not a template.

    Thanks for taking the time, I’ll look into now.

    Perfect! Thanks adtowle! Your code fixed my problems with my menu disappearing on the archive by categories! Thanks for posting.

    awesome – this sorted my issue as well where my navigation was not appearing on my search page.

    hello im using the Chateau Theme and I’m having a problem with the menu disappearing once I click on a sub category. I have “planks” and “articles” as an example…could I be using that same code you showed? please help me, this is really frustrating…

    http://www.exercisingcap.com/ (no problem seeing the main navi)

    Both of these menu/sub are categories and the main navi disappears:
    http://www.exercisingcap.com/articles/
    http://www.exercisingcap.com/activities/

    Thank you and I hope someone can help me with this…

    @adtowle

    This solution is great, except that you lose the built-in “current-menu-item, current_page_ancestor, etc.” classes in the process.

    So, I just wrapped it in:
    if ( is_category() ):

    That way you maintain those classes when you’re on a regular page. This whole thing really does seem hacky, but I can’t seem to find any better solution.

    where do you put this code?

    <?php 
    
    $backup_query = $wp_query;
    $wp_query = new WP_Query(array('post_type' => 'post'));
    
    wp_nav_menu( array( 'theme_location' => 'guides' ) ); 
    
    $wp_query = $backup_query;
    
    ?>
    Becky Davis

    @bdgardengirl

    WCEU 2016 Contributor

    jcc2150 – you put this code in your header.php file, presumably where you are calling menus. Just replace your
    wp_nav_menu( array( 'theme_location' => 'guides' ) ); with the whole section. Obviously, if your menu is not called “guides” you need to change that as well.

    What I would love to hear is why this is necessary at all. I ran across this in an _s theme as well and while this fixes missing menus in a archive.php page, I certainly don’t know why. Anyone else have any insight into this?

    Becky Davis

    @bdgardengirl

    WCEU 2016 Contributor

    I did some more research into this and in my case it was a plugin that was causing the menus to stop working on category or archive pages. De-activating Add Tags And Category To Page And Post Types fixed this issue and I can now take out the funky code wrapped around my menu.
    This does appear to be an issue with this plugin and custom post types.
    http://dineshkarki.com.np/forums/topic/causes-main-menu-to-disappear

    Thank you soo much @adtowle for pointing the hacky code, @d.keeling for the category hacking and @beckyddesign for the last point. Thinking about using another plug-in for adding categories to my pages.

    Thank you all for the help. I got the menu to show on all pages now, but I still have one problem. The current_page_item class isn’t being added to the current viewed page. Is it only me?

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘[Resolved] Menus not displaying on archive pages’ is closed to new replies.