Archived topic
Masonry
10 replies · Started by Philippe on July 6, 2019
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!
Hi there,
Does this help?
https://docs.generatepress.com/article/exclude-categories-from-posts-page/
Let me know :)
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.
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;
}
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;
}
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
Hi David,
Which of the two methods are you referring to?
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
The category url should show something like: http://[yoursite]/wp-admin/edit-tags?action=edit&taxonomy=category&post_type=post&tag_ID=4&post_type=post
It shows instead: https://onehomeplanet.com/wp-admin/edit.php?category_name=bookclub
What am I missing?
Yay! I eventually found the category ID. Thanks again for your help.
Awesome - glad to be of help - yeah i wish WP actually added the ID in the editor - would make it easier to find lol