-
AuthorPosts
-
June 17, 2016 at 1:54 pm #649762
Hello,
I’ve been trying to solve this problem myself for hours, but can’t get it to work properly.
Here’s my question: I would like to add a custom “read more” link beneath each item in the masonry blog view, that gets populated with data from Advanced Custom Fields for linktext and linktarget. To achieve this, I need to output the link beneath each item and remove the A container that is wrapping each masonry blog post item.
I am able to put together the link just fine, but I fail at removing the A container and replacing it with a DIV – the layout gets messed up & the posts are not shown next to each other but underneath each other, every item in fullwidth (although I’m setting all the css classes that were used on the A container before).I used this code in my functions.php:
add_filter( 'avf_masonry_loop_prepare', 'avf_masonry_loop_prepare_mod_cat', 10, 2 ); function avf_masonry_loop_prepare_mod_cat( $key, $entries ) { $linktext = get_field('linktext', $key['ID']); $linktarget = get_field('linkziel', $key['ID']); if ( empty( $linktext ) ) { $linktext = "Mehr >"; } if ( empty( $linktarget ) ) { $linktarget = $key['url']; } $key['text_after'] .= " <span class='masonry-more-link-arrow'><a href='" . $linktarget . "' target='_self' class='readmore'>". $linktext ."</a></span>"; return $key; }
And this Javascript code:
jQuery('document').ready(function(){ jQuery('a.av-masonry-entry').wrapInner('<div class="masonry-element"></div>'); jQuery('.masonry-element').addClass('av-masonry-entry isotope-item post type-post status-publish format-standard has-post-thumbnail hentry category-aktuelles av-masonry-item-with-image av-masonry-item-loaded'); if ( jQuery('.masonry-element').parent().is( "a" ) ) { jQuery('.masonry-element').unwrap(); } jQuery( '.masonry-element.av-masonry-entry:empty' ).remove(); });
I hope I could make my problem clear!
Thank you in advance for your help!
- This topic was modified 8 years, 5 months ago by gugler. Reason: Usage of in text messed up the display ;)
June 20, 2016 at 2:25 pm #650821Hi,
Open /config-templatebuilder/avia-shortcodes/av-helper-masonry.php and look for line:
$this->loop[$key]['html_tags'] = array('a href="'.$this->loop[$key]['url'].'"','a'); //opening and closing tag for the masonry container
Replace it by this:
$this->loop[$key]['html_tags'] = array('div','div');
Regards,
JosueJune 20, 2016 at 3:16 pm #650860Hello Josue,
Thank you for this recommendation, I have tried it and it works! As I’m using a Child Theme, I’d rather not change the Enfold Parent – is there a way I can incorporate this change in my child theme as well?
Best regards,
StephanieJune 20, 2016 at 3:18 pm #650863Hi!
Please refer to this post – http://kriesi.at/documentation/enfold/add-new-or-replace-advanced-layout-builder-elements-from-child-theme/
Cheers!
YigitJune 20, 2016 at 4:29 pm #650927Hi Yigit, Thank you for your helpful comment, I got it running now! :)
Best regards
Stephanie -
AuthorPosts
- The topic ‘Masonry Blog – Add Custom 'Read more' link with Advanced Custom Fields’ is closed to new replies.