[Resolved] hidden category page Blog

Home Forums Support [Resolved] hidden category page Blog

Home Forums Support hidden category page Blog

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1089514
    alexis

    Hi..,
    Sorry I didn’t find an answer to my problem:
    I want certain categories (e. g. projects) not to appear on the blog page.
    I used this function incorrectly:

    add_filter('pre_get_posts', 'excludeCat');
    function excludeCat($query) {
          if ( $query->is_blog ) {
                $query->set('cat', 'projets');
          }
          return $query;
    }

    Which php code to include please ?

    #1089549
    David
    Staff
    Customer Support
    #1089576
    alexis

    Yes, but it doesn’t work. By which I replace “is_home” as I am the blog page?. And the’3, 5 and 23′ I replaced them with the project categories (name of my category of articles)

    #1089586
    David
    Staff
    Customer Support

    You can see the top level conditional tags here:

    https://docs.generatepress.com/article/using-hooks-conditional-tags/#blog-posts-page

    is_home is the Blog Page not to be confused with the is_front_page which is the home page.

    The query must use the ID of the category – not its slug.
    Edit the category you wish to exclude and inspect the URL within you will see eg. ID=4

    The exclude query will then look like:

    $query->set('cat', '-4');

    Note the - must remain as this is what removes the category.

    #1089745
    alexis

    Thank you very much! Sorry I was missing some elements but with these explanations I understand. It works well. This is my first site with this theme which is very good for customization

    #1089754
    David
    Staff
    Customer Support

    I must say that WP’s naming conventions can scramble the brains a little. Glad to be of help and happy to hear your liking GPP

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