-
AuthorPosts
-
September 28, 2016 at 9:52 pm #692884
Hi all!
On a homepage I have two masonry grids:
- First grid pulls only posts in the “Featured” category.
- Second grid displays every other category except “Featured.”
- Posts can be categorized into about 12 cats.
- And many posts fall into multiple cats.
The reason for the two grids:
- Posts gets added quiet frequently and I only show the 3 latest posts in each grid on the homepage.
- Some posts I want to stay on the homepage longer, so I flag them as “Featured” and use it sparingly.
The problem is: If I have a post flagged as “Featured” and as “category 2” it will show in both grids.
I saw the below thread to filter the query for “Category__not_in” which works, but it does it for all masonry grids.
https://kriesi.at/support/topic/exclude-category-or-tag-from-masonry-pullavoid-duplicate-posts-on-frontpage/Is there anyway to apply the above filter to only one specific masonry grid? or another way to accomplish the goal? Clear as mud? :)
October 1, 2016 at 1:20 am #694110Hey Bill,
You could wrap the filter code with:
if(is_page('2')){ .. }
So it runs only on a specific Page.
Best regards,
JosueOctober 1, 2016 at 10:13 pm #694254Good thought Josue. That takes care of part of it. It keeps it just to my homepage grids and not my news page grid, but still the challenge is that it filters both grids on the home page. I need it to filter only one grid on that page and leave the other alone.
I took a “not-so-pretty” approach to it and am using jQuery on page load to remove the grid posts that are flagged in “featured news” from grid 2. So now grid 1 shows featured news as set up in the masonry settings. Grid 2 shows all posts in the other categories and if one of them is also categorized in “Featured News” it is removed by jQuery.
October 13, 2016 at 9:27 am #698633Hi,
This is possible but you have to modify the config-templatebuilder > avia-shortcodes > av-helper-masonry.php file, look for this code around line 648:
$query = apply_filters('avia_masonry_entries_query', $query, $params);
.. replace it with:
$query = apply_filters('avia_masonry_entries_query', $query, $params, self::$element);
And then replace the code in the functions.php file with the following.
add_filter('avia_masonry_entries_query', 'avia_masonry_entries_query_mod', 10, 3); function avia_masonry_entries_query_mod( $query, $params, $masonry ) { if(is_page(2) && $masonry == 1) { $exclude_cat = array('category__not_in' => '3'); $query = array_merge((array)$exclude_cat, (array)$query); } return $query; }
The code should affect the page with the id of 2 and the first masonry element.
Best regards,
IsmaelOctober 13, 2016 at 7:00 pm #698866Excellent! This is sounding pretty promising!
I’m guessing this is true since you guys build this theme so smartly! But, will the av-helper-masonry.php file work the same way as my customized template builder elements if I drop it into the “shortcodes” folder for my child theme? So I don’t disrupt the core theme files which would override on an update?
October 14, 2016 at 6:08 am #698968Hi,
That’s the catch, unfortunately, you can’t override this file in a child theme.
Best regards,
IsmaelOctober 14, 2016 at 6:29 pm #699257No worries! If I document well enough, this would be manageable. I’ll give it a test and weigh the pros and cons vs my jQuery solution, which seems to be working. Since this is our intranet, I have more liberties knowing what the client side is, so I may default to jQuery.
Thanks for looking into it for me though as always!
October 16, 2016 at 5:17 am #699440Hey!
I am very interested with the jQuery solution if you don’t mind sharing it. :)
Cheers!
IsmaelOctober 16, 2016 at 8:17 pm #699683Each of my grids only show 3 items. To accommodate the removal of the featured news from grid 2, I load 12 items into grid 2. Then the jQuery runs on window load. Then, assuming I’ll have more than 3 items in grid 2 after the jquery, I use CSS to hide any if they exist with display:none on a:nth-childs 4 – 12.
In a custom.js file (among other things that also run on window load) I have the below.
(function($){ $(window).load(function() { jQuery('#av-masonry-2 a.category-featured-news').remove(); }); })(jQuery);
October 18, 2016 at 6:44 am #700390 -
AuthorPosts
- You must be logged in to reply to this topic.