Community Forums › Forums › Archived Forums › Design Tips and Tricks › Navigation not showing up on category archive pages
Tagged: categories, Custom Post Type, navigation
- This topic has 7 replies, 3 voices, and was last updated 8 years, 9 months ago by asbilly92.
-
AuthorPosts
-
January 9, 2015 at 4:22 pm #136794carrieoke13Participant
For some reason, on my category archive pages, there is no navigation menu. Here's an example:
http://eportfolio.uga.edu/wordpress/category/technological/
I don't have a custom template for the archive pages. I do have a custom post type, but I'm not sure if that would cause an issue? The menu is showing on all other pages, on the custom post types, on the search results page, etc. I am totally stumped.
I am using a heavily modified Foodie Pro theme.
thanks for any help!
January 10, 2015 at 6:15 am #136849CarloMemberHi Carrie. That's definitely a strange result.
You say that it's heavily modified. I took a look at the Foodie Pro demo and the menu does display on category archives, so it's not the way the theme is configured.
I also noticed another strange difference between the demo and your site, and that is that the footer element on your site is 'popped out' of the site container.
In other words, the markup structure in the theme demo is like this:
<body> <div class="site-container"> <header class="site-header"></header> <nav class="nav-primary"></nav> <div class="site-inner"></div> <footer class="site-footer"></footer> </div> </body>
But on your site, it's like this:
<body> <div class="site-container"> <header class="site-header"></header> <nav class="nav-primary"></nav> <div class="site-inner"></div> </div> <footer class="site-footer"></footer> </body>
Were you aware of that, or is that unexpected too?
Based on that, I think it may be due to a coding error somewhere.
I don't know if this will work, but try creating a new template called
category.php
and give it the following contents:<?php add_action( 'genesis_after_header', 'genesis_do_nav' ); genesis();
January 11, 2015 at 12:51 pm #137072carrieoke13ParticipantHi Carlos,
I did that on purpose - I moved the footer out of the main container so it would be full width. I did that by adding this code to my functions.php://* Reposition the footer widgets remove_action( 'genesis_before_footer', 'genesis_footer_widget_areas' ); add_action( 'genesis_after', 'genesis_footer_widget_areas' ); //* Reposition the footer remove_action( 'genesis_footer', 'genesis_footer_markup_open', 5 ); remove_action( 'genesis_footer', 'genesis_do_footer' ); remove_action( 'genesis_footer', 'genesis_footer_markup_close', 15 ); add_action( 'genesis_after', 'genesis_footer_markup_open', 11 ); add_action( 'genesis_after', 'genesis_do_footer', 12 ); add_action( 'genesis_after', 'genesis_footer_markup_close', 13 );
I tried what you suggested and it's still not showing up. I'm wondering if something in my custom functions are making it disappear? This is so weird!
January 11, 2015 at 1:02 pm #137083carrieoke13ParticipantOkay, I found the culprit, but I'm not sure how to edit it to fix the issue.
This code adds my custom post types to tags and categories:
//add custom post type to tags and categories function add_custom_types_to_tax( $query ) { if( is_category() || is_tag() && empty( $query->query_vars['suppress_filters'] ) ) { // Get all your post types $post_types = array('post' , 'articles'); $query->set( 'post_type', $post_types ); return $query; } } add_filter( 'pre_get_posts', 'add_custom_types_to_tax' );
When I comment it out, the menu reappears on my category archives, but all my custom post types that are in that category don't appear on the page anymore. Help!
January 11, 2015 at 1:11 pm #137088carrieoke13ParticipantOkay! I have found a solution, and frankly, I have no idea why it works, but someone had another problem and posted about it in the comments here: http://premium.wpmudev.org/blog/add-custom-post-types-to-tags-and-categories-in-wordpress/#comment-153788
Here's what I did: I replaced
// Get all your post types $post_types = array('post' , 'articles');
in the above code with
$post_types = array( 'nav_menu_item','articles', 'news' );
and magically, my menu is back!
thanks so much for pointing me in the right direction!
January 12, 2015 at 9:50 am #137175CarloMemberI see now. The reason your menu wouldn't show is because the function set the allowed post types to
'post'
and'articles'
. The post type for menu items is'nav_menu_item'
. So all your menu items were blocked from showing.However, the code you've implemented now might still have some issues. Firstly, it's excluding
'post'
and including'news'
(which you weren't doing before) and it also might cause your menu items to display in the main loop.I actually run very similar code on my own site, but I use
$query->is_main_query()
so that the post type manipulation runs for the main loop only and not the menu. You can use this code instead if you like://add custom post type to tags and categories function add_custom_types_to_tax( $query ) { if( ( $query->is_category() || $query->is_tag() ) && $query->is_main_query() ) { // Get all your post types $post_types = array('post' , 'articles'); $query->set( 'post_type', $post_types ); } return $query; } add_filter( 'pre_get_posts', 'add_custom_types_to_tax' );
January 12, 2015 at 11:26 am #137202carrieoke13ParticipantThank you, Carlo! This works beautifully.
February 19, 2016 at 7:14 am #179384asbilly92ParticipantOMgosh!! I just have to say THANK YOU THANKS for this post thread!!
I just had the exact issue, been struggling with it for 2 days; after finally getting my CPT's to show up in the archives then poof my nav menu went bye bye agggg, BUT this fixed it!!!
Be lost without these forums!!
-
AuthorPosts
- The topic ‘Navigation not showing up on category archive pages’ is closed to new replies.