-
AuthorPosts
-
November 14, 2014 at 11:18 pm #351559
Hey there,
I’m using Masonry to display main blog posts on the homepage and am going to build a page for audio posts only. I would like SOME but not all of the audio posts to appear on homepage. Is there a way I can exclude one tag or category (which I would then create for these audio-page-only posts) from Masonry, or do I need to select ALL categories in order to exclude one?
Slightly related, I am using Blog Posts to display one post in full above the Masonry layout. How do I exclude that post from displaying in the Masonry grid as well?
Thank you enormously :) Elizabeth
November 15, 2014 at 9:21 am #351738Hi ElizabethB!
Thank you for using Enfold.
Yes, you need to select all categories that you want to show then leave the excluded categories. Or use this on functions.php to exclude certain categories by id:
add_filter('avia_masonry_entries_query', 'avia_masonry_custom_query'); function avia_masonry_custom_query( $query ) { $exclude_cat = array('category__not_in' => '49'); $query = array_merge((array)$exclude_cat, (array)$query); return $query; }
Add category ids on the category__not_in parameter. Refer to this link for more info: http://codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters
Cheers!
IsmaelJuly 25, 2018 at 4:38 am #989473Hi, (slightly) related to this question, I use the ‘Magazine’ element to display posts on my front page.
I have a setup:
– Category 1
– -Subcat 1
– -Subcat 2
– -Subcat 3
-Category 2I have some posts which belong to a subcategory of Category 1 and also belong to Category 2
The Magazine element for Category 1 shows all posts of all subcategories. However, I don’t want it to show posts which are also included in Category 2. Is there a filter I can add to functions to not show posts in Magazine element for Cat1 if they also belong to Cat2? Thanks
Edit: I know that I can exclude duplicates. I am just searching for a way to exclude posts labelled Cat1+Cat2 from the Magazine element for category 1, but to include them in the category page for category 1 (http://my.domain.com/category/category1).
Thanks
- This reply was modified 6 years, 4 months ago by medi-paper.
July 26, 2018 at 2:54 pm #990272Hi,
You can tr to combine the category__not_in with the category__in parameter like:
add_filter('avia_masonry_entries_query', 'avia_masonry_custom_query'); function avia_masonry_custom_query( $query ) { $exclude_cat = array("category__in" => array(1), "category__not_in" => array(2)); $query = array_merge((array)$exclude_cat, (array)$query); return $query; }
Replace 1 with the category id of category 1 and 2 with the category id of category 2.
Best regards,
DudeJuly 26, 2018 at 5:06 pm #990319Hi, thanks.
I just tried but to no avail.Just to confirm, is the avia_masonry_entries_query applicable to the ‘Magazine’ element?
Thanks once more
July 26, 2018 at 7:22 pm #990362Hi,
No, I thought you want to change the masonry element (like mentioned in the first post). If you want to change the magazine query use this code:
add_filter('avf_magazine_entries_query', 'avia_magazine_custom_query', 10, 2); function avia_magazine_custom_query( $query, $params ) { $exclude_cat = array("category__in" => array(1), "category__not_in" => array(2)); $query = array_merge((array)$exclude_cat, (array)$query); return $query; }
Best regards,
DudeJuly 27, 2018 at 4:55 am #990536Thanks Dude, however, that excludes Category 2 completely from all magazine elements (even from the magazine element supposed to show Category 2 only), not just from the magazine element supposed to be showing Category 1.
July 29, 2018 at 6:41 pm #991158Hi,
I haven’t tested it but you can try to use the css class field to apply the code to certain magazine elements only.
1) Activate the css class option field: https://kriesi.at/documentation/enfold/intro-to-advanced-layout-builder/#turn-on-custom-css-class-field-for-all-alb-elements
2) Insert the css class “avf_remove_duplicate_cats” (without the quotes) into the field (magazine element you want to filter)
3) Save the elements/page
4) Add this code to the funtions.php file
add_filter('avf_magazine_entries_query', 'avia_magazine_custom_query', 10, 2); function avia_magazine_custom_query( $query, $params ) { if(!empty($params['class']) && strpos($params['class'], 'avf_remove_duplicate_cats') !== false) { $exclude_cat = array("category__in" => array(1), "category__not_in" => array(2)); $query = array_merge((array)$exclude_cat, (array)$query); } return $query; }
and replace 1 and 2 with your category ids.
Best regards,
DudeJuly 30, 2018 at 4:34 am #991364Thanks, Dude. That did the trick! Much appreciated.
July 30, 2018 at 7:26 am #991419Hi,
Awesome! Glad we could help!
Please take a moment to review our theme and show your support https://themeforest.net/downloads
Don’t forget to bookmark Enfold Documentation for future reference.Thank you for using Enfold :)
Best regards,
Ismael -
AuthorPosts
- The topic ‘Exclude category or tag from Masonry pull/avoid duplicate posts on frontpage’ is closed to new replies.