Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #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 ;)
    #650821

    Hi,

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

    #650860

    Hello 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,
    Stephanie

    #650863
    #650927

    Hi Yigit, Thank you for your helpful comment, I got it running now! :)

    Best regards
    Stephanie

Viewing 5 posts - 1 through 5 (of 5 total)
  • The topic ‘Masonry Blog – Add Custom 'Read more' link with Advanced Custom Fields’ is closed to new replies.