Viewing 27 posts - 1 through 27 (of 27 total)
  • Author
    Posts
  • #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,
    Eoghan

    #762829

    Hey 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 Torvik

    #763833

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

    #764598

    Hi,

    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 Torvik

    #765423

    Thanks 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,
    Eoghan

    #765951

    Hi,

    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 Torvik

    #766906

    Hi 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,
    Eoghan

    #769744

    Hi,

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

    Are 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,
    Ismael

    #775671

    Hi 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,
    Eoghan

    #775759

    Hi!

    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,
    Ismael

    #776654

    Hi 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,
    Eoghan

    #777184

    Hey!

    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,
    Ismael

    #990186

    Hi, 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?

    #990457

    Hi,

    .widget_categories option:nth-of-type(22) {
    display: none;
    }

    and let us know if it works

    Best regards,
    Basilis

    #990528

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

    #991398

    Hi,

    Where can we see the page? Please provide a link so that could inspect it.

    Best regards,
    Ismael

    #991422

    Hi 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

    #991822

    Hi,

    Thanks for that. I can’t see the category widget though. Do we need to login to see that widget?

    Best regards,
    Ismael

    #995235

    Hi 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

    #995336

    Hi,

    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,
    Ismael

    #995337

    Hi,

    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,
    Ismael

    #996125

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

    #996539

    Hi,

    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,
    Ismael

    #997169

    Hi 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

    #997420

    Hi,

    Thanks for the update.

    I’ll ask the team to check the thread. Please wait for their response.

    Best regards,
    Ismael

    #997476

    Thanks Ismael

    #997492

    Hey!

    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

Viewing 27 posts - 1 through 27 (of 27 total)
  • You must be logged in to reply to this topic.