Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #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? :)

    #694110

    Hey Bill,

    You could wrap the filter code with:

    if(is_page('2')){
    ..
    }

    So it runs only on a specific Page.

    Best regards,
    Josue

    #694254

    Good 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.

    #698633

    Hi,

    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,
    Ismael

    #698866

    Excellent! 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?

    #698968

    Hi,

    That’s the catch, unfortunately, you can’t override this file in a child theme.

    Best regards,
    Ismael

    #699257

    No 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!

    #699440

    Hey!

    I am very interested with the jQuery solution if you don’t mind sharing it. :)

    Cheers!
    Ismael

    #699683

    Each 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);
    #700390

    Hey!

    That’s a pretty nice solution. Thanks for sharing. :)

    Cheers!
    Ismael

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