Jump to content

Taking first image from post


Gil Ronen

Recommended Posts

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}}

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...