1

The article element are the post in that category[service], my question is aside from display:none; the article, how to remove those post in category page in Genesis Wordpress using genesis way or hooks.

enter image description here

marky939
  • 43
  • 7

1 Answers1

1

In Genesis you should be able to go to Genesis > Theme Settings and under Blog Page Template you can exclude posts from the blog page based on the ID.

If your child theme doesn't support that option of you just want a solution that is more generalized, here's some code that's not Genesis specific - add this to your functions.php file. It will check to make sure it's the main post query on am archive page before running. Just replace 100 with the category ID you want removed (make sure to keep the minus sign)

<?php
    add_action( 'pre_get_posts', 'marky939_remove_cat' );
    function marky939_remove_cat( $query ){
        if( is_archive() && $query->is_main_query() ){
            // Replace "100" with the ID for the Service category.
            $query->set( 'cat', '-100' );
        }
    }
?>
Xhynk
  • 13,513
  • 8
  • 32
  • 69
  • My pleasure, I'm glad I could help! – Xhynk Mar 05 '18 at 07:06
  • sir xhynk, actually theres flaw with that snippet, it also remove the post of subcategory of that category. – marky939 Mar 07 '18 at 06:49
  • It will remove any post that is in that category, thus remove the child categories as well - that's intentional WordPress functionality (and standard hierarchy). You shouldn't be excluding `Category A` and then including Cat A's child categories. If you need a more complex query that does that, check out the docs for [`pre_get_posts`](https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts) - you can add more paremeters such as `$query->set( 'category__and', array( 1, 101 );` where "1" is your main category and "101" is a subcategory of "Service" – Xhynk Mar 07 '18 at 07:29