I want to display the list of related posts at the end of my blog post. I would like the main image to display if possible, but I can't seem to get this to work right. Any help would be a appreciated.
So when you execute that foreach loop above, does it loop through all the related posts for the selected post and output the main_image for each related post or does it output something different and if so what does it output for each related post main_image value?
Hmm...I'm not able to replicate this issue. I tested it with the following and it behaved as expected: $related = $post->related_posts;
foreach($post->related_posts as $p) :
echo '<img src="'.$p->thumbnail_image.'"><br>';
endforeach;
Comments
foreach($post->related_posts as $related) : echo $related->main_image; endforeach;
I also removed "endforeach;" because it caused an error.
Here's what I have:
php foreach($post->related_posts as $related)
php if (!empty($related)) :
php echo $related->thumbnail_image
php endif;
echo $related->main_image;
It still isn't showing all the images. It's only showing 1 image.
I tried the suggested:
echo $related->main_image;
but it gave me the same results with the main image. It only displays one.
$related = $post->related_posts; foreach($post->related_posts as $p) : echo '<img src="'.$p->thumbnail_image.'"><br>'; endforeach;
Where it echo's the image src I had to include a path to the folder for the images to load.
echo '<img src="/assets/images/blog'.$p->thumbnail_image.'"><br>';
Thank you.