Jump to content

image from a random page... getting it to link


Alex
 Share

Recommended Posts

Hi,

I'm displaying an image on the homepage from a group of sub pages which all use the same template.

I can display the image fine, and it is random. I can't work out how to get the image to link to it's page?

My code below when you click the image it just keeps cycling through the random images.

$image = $pages->get("template=artworks-child, sort=random")->artworks_thumb->getRandom();
$thumb = $image->size(550, 0);
echo "<a href='{$page->url}'><img src='{$thumb->url}'></a>";
Link to comment
Share on other sites

store the page in a variable, and get the image only later:

$randomPage = $pages->get("template=artworks-child, sort=random");
$image = $randomPage->artworks_thumb->getRandom();
$thumb = $image->size(550, 0);
echo "<a href='{$randomPage->url}'><img src='{$thumb->url}'></a>";
  • 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

  • Recently Browsing   0 members

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