I created a portfolio page with fetching my portfolio items in a loop. Sometimes there are only 1 or 2 photos in the item. Is it somehow possible to get the masony gallery doing the columns dynamic?
you can easily do this by having the column-count as a variable, and adding a dynamic attribute to the masonry-element, with the query-result-count of your loop and some css:
Of course you have to change the grcjrj for the bricks-id of your loop-element
Hello thank for you reply. On which element I need to do this?
The scenario is:
Page with a image gallery in it which querys from the portfolio items I create. For example Martino has 3 pictures in the portfolio and Jasmina only one. I have an ACF activated with name âjs_p_portfolio_main_galleryâ which I use in the block for the query.
Sorry Iâm totally at the beginning with programming in PHP and HTML.
This can also be done. But again we need to write some code, since we canât output the ACF-field-count with the standard dynamic-data-tag of bricks (otherwise we could use bricks conditions).
I would suggest you put an Image-Element inside the query loop and we programmatically tell bricks to render either the Image-Element or the Image-gallery-Element, depnding on the itemcount of your ACF-Field.
this is what your strucutre panel should look like, and I also marked the parts that you would need to change for your code to work.
When I try setup another return variable it is not working. Or makes it sense to create another image gallery which only shows up when there are 2 elements in it?
I tried this:
add_filter(âbricks/element/renderâ, function ($render, $element) {
if ($element->name !== âimage-galleryâ) return $render;
if ($element->element[âidâ] !== âsecond_galleryâ) return $render; // change bricks-id of your Image-Gallery-Element
// $gallery_field = get_field(âimage-galleryâ, $element->post_id); // my example ACF field
$gallery_field = get_field(âjs_p_portfolio_main_galleryâ, $element->post_id); // your ACF field