Show/hide css based on categories
This topic contains 11 replies, has 4 voices, and was last updated by Paolo 8 years ago.
We have moved to a support ticketing system and our forums are now closed.
Open Support TicketTagged: category, conditional, css, hide
-
AuthorPosts
-
December 11, 2016 at 4:41 am #322956
I want to hide certain elements on individual categories…..I’ll explain…
Example:
If the category is ‘Rivers’ hide css/info* related to ‘lake size’.
If the category is ‘Lakes’ hide css/info* relates to ‘rivers’
I know I could split rivers and lakes into 2 custom post types, but I’d lose a bunch of other things like having everything neatly on the same map etc..
*custom field info
December 11, 2016 at 10:45 am #323116I don’t think that is possible. Let’s ask the others too.
December 11, 2016 at 9:35 pm #323385I suppose I’m basing it on this sort of idea with pages:
<?php // Do action only on specific page in WP ?> <?php if( in_page('johns lake') ) { ?> <style> #river_info{ display: none; } </style> <?php } ?>
Not sure if it would be possible to do the same with categories though
December 12, 2016 at 4:09 pm #323697Hi,
each page and category archive should have a unique body class.
You can use that to target your css only for specific pages.
Example: that “johns lake” page, probably has a body class like this: page-id-123 (where 123 is the page ID)
In that case you can use css like this:
.page-id-123 #river_info{ display: none; }
Hope this helps,
Let us know
December 12, 2016 at 7:33 pm #323826Useful to know, so I could potentially edit out info on a case by case basis when new pages get added…
But there’s no way to do it for an entire category by the sound of it.
Can you guys think of another way to keep everything as one cpt but display only specific fields (or hide specific fields if it’s a different category)?
December 12, 2016 at 7:49 pm #323840Hi,
what do you mean by: “for a category”?
Archives add a custom body class to for each category.
If you provide a link of an example, I’ll point you in the right direction.
Thanks
December 12, 2016 at 8:32 pm #323848I have “Lakes” and “rivers” … Its great having both on the same map… (having individual CPTs would also be an easy way to separate data, but sometimes there are rivers and lakes on the same fishing venue). It doesn’t make sense having the question “What is the lake size?” on the add listing for rivers… but I can live with that…
What really doesn’t make sense is looking at a river such as this and clicking the ‘more info’ tab and seeing stuff about lake size… its a river, plus… pretty difficult to know the size anyway.. so it would be better just to hide that info for rivers. Equally there is info about rivers that we still have to add, but that info doesn’t apply to lakes.
Sorry if that’s super confusing! It does sound it as I’m typing it!
December 12, 2016 at 9:27 pm #323864In this case you linked the home page and a detail page.
Neither one is a category page like you mentioned.
For something like that the only option is using separate CPT.
Thanks
December 12, 2016 at 9:32 pm #323865Another suggestion is to create price packages for lakes and rivers separate, and then restrict some custom fields to the relevant categories. That way they cannot be added for that category and they will not show for that category.
December 12, 2016 at 10:27 pm #323880Genius! I think that’s it!
December 22, 2016 at 4:04 pm #329190I’m not an advanced programmer, but pieced together information from a couple different support topics and added this my child theme’s functions file to get a class for one specific GeoDirectory Place Category. Now I can style that category as I want.
function my_custom_body_class_in_category($classes) { // add 'my-class' to the my-category archive and single posts of the category. if ( has_term ( 'my_class', 'gd_placecategory' ) ) $classes[] = 'my_class'; // return the modified $classes array return $classes; } // add my custom class via body_class filter add_filter('body_class','my_custom_body_class_in_category');
December 22, 2016 at 4:22 pm #329239Way to go Anitra and thanks for sharing! 🙂
-
AuthorPosts
We have moved to a support ticketing system and our forums are now closed.
Open Support Ticket