Invision Community 4: SEO, prepare for v5 and dormant account notifications Matt November 11, 2024Nov 11
Posted February 20, 20186 yr Hi, I want to take the first image from a post and use it in a widget template, how can I do this? Thanks
February 21, 20186 yr 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}}
February 24, 20186 yr Author 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?
Archived
This topic is now archived and is closed to further replies.