Tagged: categories, CSS, Hide, Widget
-
AuthorPosts
-
March 17, 2017 at 3:17 pm #762525
I’ve been trying to hide a specific category from appearing in the Categories widget in the blog sidebar.
I’ve tried following the advice in this thread: https://kriesi.at/support/topic/how-to-exclude-one-category-from-category-widget/
.sidebar #categories-3 .cat-item-4 { display:none !important; }
(Changing it to #categories-2, which seems to be the id of the widget on single posts for my site, and .cat-item-97, as 97 is the ID of the category I want to hide.)
Here’s a single post page with the Categories widget:
I’ve removed the CSS for now as it wasn’t working.
Any advice? What am I doing wrong?
Thanks,
EoghanMarch 18, 2017 at 6:19 am #762829Hey thatcommsguy,
The code that you used to remove a category will work if you show the category as regular (when all the items are a list). But in your case, the categories are showed in a drop down, so, to remove a specific category, follow theses steps below:
1. Inspect the category drop down and you`ll see each item and exclusive values -> see here: http://prntscr.com/eldccp
2. Now, to remove the categories that you want, add this custom CSS code at Enfold theme options > general styling > Quick CSS
.widget_categories option[value="42"] { display: none; }
You can see that I remove the category with the value 42, you just need to change this value to remove the category.
That`s it! :)
Best regards,
John TorvikMarch 20, 2017 at 10:20 pm #763833Thanks so much John. That’s worked perfectly.
Can I tack on a follow-on question, not unrelated?
I’ve now hidden category ID 97 (“Collaboration by Design”) from both the dropdown and from the Masonary blog view that appears on the blog homepage. However, if I click on this post:
…the left-hand pager arrow that allows me to jump to the previous blogpost jumps to a post that is in category 97:
I can’t work out how to also exclude that category from appearing at all when clicking through the posts in that way.
(I the code below in functions.php to exclude the posts from my RSS feed, which is picked up by a MailChimp campaign:)/* Excluding the Collaboration By Design category from the RSS feed so it doesn't get picked up by MailChimp */ function exclude_category($query) { if ( $query->is_feed ) { $query->set('cat', '-97'); } return $query; } add_filter('pre_get_posts', 'exclude_category');
Thanks in advance.
EoghanMarch 22, 2017 at 6:55 am #764598Hi,
You just need to use the is_singular, like this code:
function exclude_category( $query ) { if ( $query->is_singular(‘post’) && $query->is_main_query() ) { $query->set( 'cat', '-97' ); } } add_action( 'pre_get_posts', 'exclude_category' );
Best regards,
John TorvikMarch 23, 2017 at 1:44 pm #765423Thanks John.
As it won’t let me redeclare “exclude_category”, which I’ve already declared in the is_feed above, can you tell me what the syntax is for adding this is_singular snippet to the code. Is it something like this?
function exclude_category($query) { if ( $query->is_feed ) { $query->set('cat', '-97'); } return $query; } add_filter('pre_get_posts', 'exclude_category'); if ( $query->is_singular(‘post’) && $query->is_main_query() ) { $query->set( 'cat', '-97' ); } } add_action( 'pre_get_posts', 'exclude_category' );
(I know what I’ve pasted above does not work, but I’m not sure how to fix it.)
Thank you again,
EoghanMarch 24, 2017 at 7:06 am #765951Hi,
You can use this code to work correctly:
function exclude_category($query) { if ( $query->is_feed ) { $query->set('cat', '-97'); } if ( $query->is_singular(‘post’) && $query->is_main_query() ) { $query->set( 'cat', '-97' ); } return $query; }
Best regards,
John TorvikMarch 26, 2017 at 11:02 am #766906Hi John,
Thanks for your continued help with this. I’m afraid the code above is not working either. I have tried using just your code, and also that code with the filter added (in case that was having an impact on where it was called) as follows:
function exclude_category($query) { if ( $query->is_feed ) { $query->set('cat', '-97'); } if ( $query->is_singular(‘post’) && $query->is_main_query() ) { $query->set( 'cat', '-97' ); } return $query; } add_filter('pre_get_posts', 'exclude_category');
To be clear, while the “Collaboration by Design” category (97) no longer appears in the dropdown menu in the Categories widget, it is still being called when navigating through the blog using the next and previous post buttons. For example, on this page:
…the previous post is one from Category 97.
I’m wondering whether I need to be specifying that my exclusion request applies to the avia-post-prev (and -next) situations?
Sign-in details in the private box…
Thanks,
EoghanMarch 31, 2017 at 7:23 am #769744Hi,
https://brightgreenlearning.com/2017/02/last-mile-learning.html
…the left-hand pager arrow that allows me to jump to the previous blogpost jumps to a post that is in category 97:
https://brightgreenlearning.com/2016/12/learned-academy-brian-mckenna.htmlAre you referring to the post navigation at the edge of the screen? Are these posts contained in the same category? If not, you can use the following filter in the functions.php file to fetch the posts in the same category.
add_filter('avia_post_nav_settings', 'avia_post_nav_settings_mod'); function avia_post_nav_settings_mod($settings) { $settings['same_category'] = true; return $settings; }
Best regards,
IsmaelApril 10, 2017 at 9:53 pm #775671Hi Ismael,
Thanks for helping with this. Maybe it’s best if I explain from the start, but in brief:
– There’s a blog on the website, using multiple categories, here: https://brightgreenlearning.com/blog
– There’s also a blog, but using only one category (97, ‘Collaboration by Design’), here: https://brightgreenlearning.com/academy/collaboration-by-design
– I would like both the main blog (multiple catgories) and the single-category blog to be entirely separate from the visitors point of view. So I have managed, for example, to have a different sidebar show up on posts that are in category 97 and also to have that category hidden from the sidebar categories widget that appears on the main blog.What I have not been able to do is to stop the post navigation at the edges of the screen from A) excluding category 97 when browsing the main blog and B) showing only category 97 when browsing the alternative blog?
I could potentially solve this by just disabling that navigation option altogether, but it does add some value for site visitors, so I’d rather keep it there.
@John Torvik tried helping me above, but the proposed solutions have not worked.If you have any suggestions I’d be most grateful.
Thanks,
EoghanApril 11, 2017 at 3:34 am #775759Hi!
What I have not been able to do is to stop the post navigation at the edges of the screen from A) excluding category 97 when browsing the main blog and B) showing only category 97 when browsing the alternative blog?
Did you try the filter that we provided above? Please note that the post navigation will filter through posts as long as they belong to the same category. Make sure that all posts within “category 97” don’t belong to any other categories.
Best regards,
IsmaelApril 12, 2017 at 2:14 pm #776654Hi Ismael,
I had not tried the code you suggested as it seemed to me that it would not deliver what I am looking for. I have now tried it and indeed found that to be case.
In the secondary blog that uses only one category (97, ‘Collaboration by Design’; here: https://brightgreenlearning.com/academy/collaboration-by-design) it works fine, with the page navigation limited to that specific category. (The posts in that blog don’t belong to any other category.
However, in the primary blog ( https://brightgreenlearning.com/blog) posts have multiple categories. The code you suggested (which I have left in place in functions.php for now) therefore means the page navigation jumps to the next post which shares one category with the current post, rather than the next oldest or newest post.
Is there some way of having that code apply only to the first of those two blog loops, but not to the primary, multi-category blog?Thanks,
EoghanApril 13, 2017 at 11:32 am #777184Hey!
Is there some way of having that code apply only to the first of those two blog loops, but not to the primary, multi-category blog?
I’m sorry but that’s not possible. The navigation will get every posts that have the same categories. The only solution is to remove other categories for the posts or hide the post navigation completely.
#top .avia-post-nav { display: none; }
Best regards,
IsmaelJuly 26, 2018 at 11:22 am #990186Hi, I have tried the instructions to remove a category from the dropdown using the code:
.widget_categories option[value=”42″] {
display: none;
}Pls see the screenshot (link in private content), it is not working on my website. What am I doing wrong?
July 26, 2018 at 9:40 pm #990457Hi,
.widget_categories option:nth-of-type(22) {
display: none;
}and let us know if it works
Best regards,
BasilisJuly 27, 2018 at 3:50 am #990528Sorry Basilis, I seem unable to hide the category in the sidebar dropdown. I did assure that the new CSS was loaded and active by checking the page source. Not sure why this is not working well.
July 30, 2018 at 6:07 am #991398Hi,
Where can we see the page? Please provide a link so that could inspect it.
Best regards,
IsmaelJuly 30, 2018 at 7:29 am #991422Hi Ismael, the page is my front page, https://medi-paper.com
Please see links to screenshots of the source in the private content.
Thanks so much
July 31, 2018 at 8:21 am #991822Hi,
Thanks for that. I can’t see the category widget though. Do we need to login to see that widget?
Best regards,
IsmaelAugust 9, 2018 at 5:43 am #995235Hi Ismael.
Sorry for my belated reply. I was travelling the past week.I have changed the dropdown to public, you should now be able to see it.
Thanks
August 9, 2018 at 10:04 am #995336Hi,
This seems to work properly. It removes the “Cardiovascular” option.
.widget select[name="cat"] option[value="129"] { display: none; }
Adjust the value attribute.
Best regards,
IsmaelAugust 9, 2018 at 10:04 am #995337Hi,
This seems to work properly. It removes the “Cardiovascular” option.
.widget select[name="cat"] option[value="129"] { display: none; }
Adjust the value attribute.
Best regards,
IsmaelAugust 10, 2018 at 6:29 pm #996125Hi Ismael,
Thanks. I noticed there may be a difference in interpretation between the latest Safari on MacOS and Google Chrome. I managed to hide several categories using your code on Google Chrome, but on Safari they are pretty persistent. Note that I have deleted all cache on Safari, switched off Cloudflare caching (hence I was able to see the result on Chrome), and put Cloudflare into “development mode”.Thanks though for the always great support.
August 13, 2018 at 6:23 am #996539Hi,
Thanks for the update. What happens when you add the !important rule?
.widget select[name="cat"] option[value="129"] { display: none !important; }
You can also try the nth-child pseudo class.
#categories-2 form select option:nth-child(5) { display: none !important; }
Best regards,
IsmaelAugust 14, 2018 at 5:41 pm #997169Hi Ismael,
The !important addition I had already tried, it didn’t work.The code
#categories-2 form select option:nth-child(5) {
display: none !important;
}Did nothing in Safari.
Appreciate the follow-up though. Thanks
August 15, 2018 at 5:40 am #997420Hi,
Thanks for the update.
I’ll ask the team to check the thread. Please wait for their response.
Best regards,
IsmaelAugust 15, 2018 at 9:42 am #997476Thanks Ismael
August 15, 2018 at 10:37 am #997492Hey!
Well the code is there, but Safari decides to interpret it the way it wants. You might want to use JavaScript to remove that element from the select.
Cheers!
Victoria -
AuthorPosts
- You must be logged in to reply to this topic.