Jump to content

Image field in news post


gregory
 Share

Recommended Posts

Hello guys, how can I view the image field? I need to view the Image associated to the post of the news. Thank you

Spoiler

<?php
echo "<div class='row'>";
	$stories = $page->children("limit=4, sort=-date");

	foreach($stories as $story) {
	   echo "
			 <div class='col-lg-3'>
				 <img src='{$image->url}' alt='{$image->description}' />
			 </div>";
		 echo "
       <div class='col-lg-9'>
				 <h1><a href='{$story->url}'>{$story->title}</a></h1>
	       <p><strong>Date:</strong> {$story->date}</p>
	       {$story->body}
       </div>
       ";

	}
echo "</div>";
?>

 

Link to comment
Share on other sites

<img src='{$story->imagefieldname->url}' alt='{$story->imagefieldname->description}' /> // single image field
<img src='{$story->imagefieldname->first()->url}' alt='{$story->imagefieldname->first()->description}' /> // multiple images selecting the first

https://processwire.com/api/ref/pageimages/
https://processwire.com/api/ref/pageimage/

  • Like 4
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...