Jump to content


Photo

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


  • Please log in to reply
2 replies to this topic

#1 Alex

Alex

    Full Member

  • Members
  • PipPipPip
  • 78 posts
  • 5

  • LocationMelbourne, Australia

Posted 17 May 2012 - 08:32 AM

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>";


#2 diogo

diogo

    Hero Member

  • Moderators
  • 1,999 posts
  • 1076

  • LocationPorto, Portugal

Posted 17 May 2012 - 09:39 AM

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>";


#3 Alex

Alex

    Full Member

  • Members
  • PipPipPip
  • 78 posts
  • 5

  • LocationMelbourne, Australia

Posted 18 May 2012 - 06:44 AM

thanks Diogo, I get it now




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users