Jump to content

Get image from multiple pages based on current page selection


Jonathan
 Share

Recommended Posts

It's late so forgive me if I make no sense. 

context: This is for a film database

How can I pull a specific image from another page based on a selection from the current page?

So, I am selecting a classification/rating for the film (e.g PG) - this works great and I am outputting the title of the selected page on the front-end.

On each of the classification pages, I created an image field for a single image and uploaded the respective classification image/logo.

Here's the code I used to echo the page title:

<?php $rating = $page->classification; echo "<a href='{$rating->url}'>{$rating->title}</a>";

I thought I'd be able to echo the image by adding:

<img src='{$rating->image}'>

but no such luck.

Thanks in advance!

J

Link to comment
Share on other sites

Make sure the image field is set to 1 image only, otherwise it will be an array.

You have taken the right route to get to the image field, though you don't really need to set up a separate $rating variable.

$page->classification->image_field, and then add ->url to output the url

echo "<img src='{$page->classification->image_field->url}' alt='{$page->classification->title}'>";
  • 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

  • Recently Browsing   0 members

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