Jump to content

Images not showing in search results


Aquostic
 Share

Recommended Posts

Hi,

I have been trying to display an image in my search results, but only get the broken image.

the code is

foreach($matches as $match) {
				echo "<img src='$match->$pic->url'>";
				echo "<a href='$match->url'>$match->title</a>";
				echo "<div class='summary'>$match->summary</div></li>";
			}

			echo "</ul>";

Screen Shot 2016-12-29 at 13.22.45.png

What am I missing here?

Cheers

Link to comment
Share on other sites

Where do you define $pic ?

Is "pic" the name of your images field? In this case you would want $match->pic->url

Also, check the max files setting of that field. If it's not "1", then it will return an array of images and you'll need: $match->pic->first()->url

  • Like 1
Link to comment
Share on other sites

I usually do it this way:

if(count($match->pic)){// if pic is the fieldname and more than one image is allowed
  $resized = $match->pic->first->size(100,0);// if the image has to be smaller than original
  echo "<img src='$resized->url' width='100' alt=' '>";
}

if pic has more than one image allowed in max filers setting

  • Like 1
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...