Recent Topics

1 Jun 17, 2011 15:56    

Hi, I would like to know if it is possible to call only an image present in post content without the text.

Example, if I would like to display a short list of featured post, with simply a thumb image and the title. The thumb image will be a thumb of the first image in the post.

This is similar to



	// Display CONTENT (teaser only):
							$Item->content_teaser( array(
									'before'      => '',
									'after'       => '',
									'disppage'    => 1,
									'stripteaser' => false,
								) );

but only showing the first image without the content teaser. i.o.w. without text.

How can I do this?

Thanks.

2 Jun 18, 2011 10:10

If the image is attached to the post try this. I assume you already have an $Item object

if( $FileList = $Item->get_attachment_FileList(50) )
{	// Get first 50 attached files and filter images
	while( $File = & $FileList->get_next() )
	{
		if( ! $File->exists() || ! $File->is_image() ) continue;
		
		// Original image tag
		$original_image = '<img src="'.$File->get_url().'" alt="'.$File->dget('alt', 'htmlattr').'" '
						.'title="'.$File->dget('title', 'htmlattr').'" />';

		// Thumbnail tag
		$thumbnail = $File->get_tag( '', NULL, '', '', 'fit-80x80', '' );
		
		break; // we found the first image, exit the loop
	}
	
	if( !empty($original_image) )
	{
		echo 'Thumbnail'.$thumbnail;
		echo 'Original'.$original_image;
	}
}

Otherwise you'll have to parse post content and extract <img> tag

preg_match( 'SOME FANCY REGEXP', $Item->content, $match )


Form is loading...