Home Forums Support Masonry

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #950777
    Philippe

    Hi, Is there a way to not display particular posts in the masonry? I have long articles that belong there, and short ones that belong to a specific category I display somewhere else than the homepage. Thanks for your help!

    #950788
    Leo
    Staff
    Customer Support

    Hi there,

    Does this help?
    https://docs.generatepress.com/article/exclude-categories-from-posts-page/

    Let me know 🙂

    #951108
    Philippe

    Hi Leo,

    I think that could definitely help. In the meantime, I have tried to decrease the number of posts appearing in the masonry by going to Settings/Reading. It simply does nothing. Weird. Do you know why?

    Thanks again for your help.

    #951238
    Philippe

    I have created Bookclub as a category and put the following in functions.php. No change.

    add_filter(‘pre_get_posts’, ‘excludeCat’);
    function excludeCat($query) {
    if ( $query->is_home ) {
    $query->set(‘cat’, ‘Bookclub’);
    }
    return $query;
    }

    #951240
    Philippe

    The “-” is being used. So that is exactly:

    add_filter(‘pre_get_posts’, ‘excludeCat’);
    function excludeCat($query) {
    if ( $query->is_home ) {
    $query->set(‘cat’, ‘-Bookclub’);
    }
    return $query;
    }

    #951244
    David
    Staff
    Customer Support

    Hi there,

    that method requires you specify the Category ID not the Slug. If you edit the category you wish to exclude then you will find the ID in the URL.

    How many posts have you set the front page to display? I am seeing only 4

    #951265
    Philippe

    Hi David,

    Which of the two methods are you referring to?

    #951282
    David
    Staff
    Customer Support

    This is the original code:

    add_filter('pre_get_posts', 'excludeCat');
    function excludeCat($query) {
          if ( $query->is_home ) {
                $query->set('cat', '-3,-5,-23');
          }
          return $query;
    }

    So -3 would exclude category ID: 3.
    This is the method you need to use. You can’t add a slug ie. -BookClub in place of the ID

    #951288
    Philippe
    #951293
    Philippe

    Yay! I eventually found the category ID. Thanks again for your help.

    #951294
    David
    Staff
    Customer Support

    Awesome – glad to be of help – yeah i wish WP actually added the ID in the editor – would make it easier to find lol

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