Site logo

[Resolved] Blog Content Template

Home Forums Support [Resolved] Blog Content Template

Home Forums Support Blog Content Template

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #2416819
    Ernst Wilhelm

    I ‘ve defined a Blog Content Template. For the Image Block I’ve enabled Dynamic Data.

    Data Source = Current Post
    Image Source = Featured Image
    Link Source = Single Image

    Single Image Directs me to the file itself, not the attachment page. Is there an option to open the attachment page via the permalink of the featured image? This is something I would really like.

    Looking forward to your answer.

    #2416987
    Ying
    Staff
    Customer Support

    Hi Ernst,

    Unfortunately GB’s image block doesn’t have this option out of the box.

    Any chance you can link me to a post with the dynamic image enabled and link me to the image’s attached page as well, so I can see if there’s a possibility to achieve this?

    #2417046
    Ernst Wilhelm

    Hy Ying. The address of my homepage is in the corresponding privat information.

    Each post has

    • an image currently linked to the file with
    • a caption, a copyright notice and as a suffix
    • a text [mehr…] linked to the attachment page.
    • a button linked to the current post.

    I coded a php snippet like this which makes the caption, copyright notice and the suffix,

    <?php
    $post_thumbnail_ID = get_post_thumbnail_ID( );
    $path =  wp_get_attachment_url($post_thumbnail_ID);
    	$info = array();
    	$data = array();
    	// Informationen des Bildes auslesen
    	$size = getimagesize($path, $info);
    	// IPTC auslesen
    	$iptc = iptcparse($info['APP13']);
    	if (is_array($iptc)) {
    		$data['iptc2#116'] = $iptc["2#116"][0];
    		$data['iptc2#120'] = $iptc["2#120"][0];
    		echo "<p style='text-align:left;font-size:80%'>" . $data['iptc2#120'] . "<br>" . $data['iptc2#116'] . " " . "[<a href='" . get_permalink( $post_thumbnail_ID ) . "'><b>mehr...</b></a>]</p>";
    	}
    ?>
    #2417090
    Ying
    Staff
    Customer Support

    I see, we can try using this filter to switch the url of the dynamic image block:

    1. Add an additional CSS class to the image block, eg. my-featured-image so we can target it in the below PHP snippet.

    2. Add this snippet:

    add_filter( 'generateblocks_dynamic_url_output', function( $url,$attributes) {
        if ( ! empty( $attributes['className'] ) && strpos( $attributes['className'], 'my-featured-image' ) !== false ) {
           $url = get_permalink( get_post_thumbnail_ID() );		
           return $url;
        }
        return $url; 
    }, 10, 2 );

    Let me know if this works.

    #2417698
    Ernst Wilhelm

    Many thanks, works great.

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