- This topic has 4 replies, 2 voices, and was last updated 3 years, 5 months ago by
Ernst Wilhelm.
-
AuthorPosts
-
November 15, 2022 at 8:39 am #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 ImageSingle 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.
November 15, 2022 at 11:11 am #2416987Ying
StaffCustomer SupportHi 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?
November 15, 2022 at 12:05 pm #2417046Ernst 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>"; } ?>November 15, 2022 at 12:52 pm #2417090Ying
StaffCustomer SupportI 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-imageso 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.
November 16, 2022 at 2:36 am #2417698Ernst Wilhelm
Many thanks, works great.
-
AuthorPosts
- You must be logged in to reply to this topic.