WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Menus not displaying on archive pages (15 posts)

  1. adtowle
    Member
    Posted 1 year ago #

    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

  2. esmi
    Forum Moderator
    Posted 1 year ago #

    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?

  3. adtowle
    Member
    Posted 1 year ago #

    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?

  4. esmi
    Forum Moderator
    Posted 1 year ago #

  5. adtowle
    Member
    Posted 1 year ago #

    Thanks for replying esmi.

    I was using underscores (_s), downloaded from:

    http://underscores.me/

    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.

  6. adtowle
    Member
    Posted 1 year ago #

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

  7. jampafoo
    Member
    Posted 1 year ago #

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

  8. Paul
    Member
    Posted 1 year ago #

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

  9. jcc2150
    Member
    Posted 6 months ago #

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

  10. d.keeling
    Member
    Posted 6 months ago #

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

  11. jcc2150
    Member
    Posted 6 months ago #

    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;
    
    ?>
  12. beckyddesign
    Member
    Posted 5 months ago #

    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?

  13. beckyddesign
    Member
    Posted 5 months ago #

    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

  14. jbruno
    Member
    Posted 4 months ago #

    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.

  15. Nyctophilic
    Member
    Posted 3 months ago #

    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?

Topic Closed

This topic has been closed to new replies.

About this Topic