Archived topic
Show Secondary Navigation on posts depending on category
11 replies · Started by dale on June 3, 2017
I found the earlier discussions where you showed how to display secondary navigation only on specified pages with this css:
.secondary-navigation {
display: none;
}
.page-id-xx .secondary-navigation {
display: block;
}
If I also want to show the secondary nav menu on posts with a certain category, would I need to use a PHP filter then?
Hi Dale,
You can try this:
.secondary-navigation {
display: none;
}
.category-xx .secondary-navigation,
.single .secondary-navigation {
display: block;
}
Thanks! That's what I'm using to have it appear on the category archive page, but it doesn't seem to work for the individual posts.
I purged caches and Cloudflare.
Try the edited code above: https://generatepress.com/forums/topic/show-secondary-navigation-on-posts-depending-on-category/#post-328103
Perfect Thanks!
You're welcome :)
I spoke to soon. I realized later that code made the secondary nav appear on all my single posts. I tried revising it as
.category-chechnya .secondary-navigation,
.category-chechnya .single .secondary-navigation {
display: block;
}
But that removed it from all single posts pages for some reason ...
Can you try this?
.category-chechnya .secondary-navigation,
.category-chechnya.single .secondary-navigation {
display: block;
}
Link me to the page if it doesn't work?
That didn't work either. Could the PHP that puts the featured image/header directly below the navigation on these category pages be interfering?
Here's an example:
https://dalecameronlowry.com/chechnya-gay-purge-26-dead-many-imprisoned/
If it's too difficult to solve, no worries. This is a would-be-nice-to-have, not a must-have.
Ahh I think you have to do something like this: https://generatepress.com/forums/topic/custom-template-for-single-post/#post-233936
Okay. I added that PHP from the link and with this CSS,
.category-chechnya .secondary-navigation,
.category-chechnya .single .secondary-navigation {
display: block;
}
I got the result I was looking for.
.category-chechnya .secondary-navigation,
.single .secondary-navigation {
display: block;
}
resulted in all posts getting secondary nav, and
.category-chechnya .secondary-navigation,
.category-chechnya.single .secondary-navigation {
display: block;
}
resulted in none getting it. just FYI.
And now with this PHP I'll be able to go hogwild with my category formatting :) Thank you!
You're welcome!