Invision Community 4: SEO, prepare for v5 and dormant account notifications By Matt Monday at 02:04 PM
Gil Ronen Posted February 20, 2018 Posted February 20, 2018 Hi, I want to take the first image from a post and use it in a widget template, how can I do this? Thanks
Adriano Faria Posted February 21, 2018 Posted February 21, 2018 Made an app once that display the last image in a post and display it on a template: function getLatestPostImage( $tid ) { $internal = \IPS\Db::i()->select( 'attachment_id', 'core_attachments_map', array( 'location_key=? and id1=?', 'forums_Forums', $tid ) ); /* Attachments */ $attachment = ''; foreach( \IPS\Db::i()->select( '*', 'core_attachments', array( array( 'attach_id IN(?)', $internal ), array( 'attach_is_image=1' ) ), 'attach_id DESC', 1 ) as $row ) { $attachment = $row['attach_location']; } if( $attachment ) { return $attachment; } return NULL; } And in template: {{$image = $topic->getLatestPostImage( $topic->tid );}} {{if $image}} <img class="ipsImage ipsImage_thumbnailed" src="{file="$image" extension="core_Attachment"}"> {{else}} <img src='{resource="no_image.png" app="rcontent" location="front"}' class="ipsThumb rcontentImage"> {{endif}}
Gil Ronen Posted February 24, 2018 Author Posted February 24, 2018 On 21.2.2018 at 1:25 PM, Adriano Faria said: Made an app once that display the last image in a post and display it on a template: function getLatestPostImage( $tid ) { $internal = \IPS\Db::i()->select( 'attachment_id', 'core_attachments_map', array( 'location_key=? and id1=?', 'forums_Forums', $tid ) ); /* Attachments */ $attachment = ''; foreach( \IPS\Db::i()->select( '*', 'core_attachments', array( array( 'attach_id IN(?)', $internal ), array( 'attach_is_image=1' ) ), 'attach_id DESC', 1 ) as $row ) { $attachment = $row['attach_location']; } if( $attachment ) { return $attachment; } return NULL; } And in template: {{$image = $topic->getLatestPostImage( $topic->tid );}} {{if $image}} <img class="ipsImage ipsImage_thumbnailed" src="{file="$image" extension="core_Attachment"}"> {{else}} <img src='{resource="no_image.png" app="rcontent" location="front"}' class="ipsThumb rcontentImage"> {{endif}} Where do I put the php code?
Recommended Posts
Archived
This topic is now archived and is closed to further replies.