Jump to content


Photo

random child page image


  • Please log in to reply
3 replies to this topic

#1 Svet

Svet

    Jr. Member

  • Members
  • PipPip
  • 14 posts
  • 3

Posted 05 May 2012 - 11:12 AM

Hi all,

Wrote this code to get one random child page and display the first image on it.
However, it is not working right. With this I always get the last child page in the array, and I want anything else but that!
$extra = $page->child("sort=random");
	
$thumb = $extra->images[0];
	
$thumb = $image->size(140, 95);

echo "<a href='{$extra->url}'><img src='{$thumb->url}' border='0'></a>";


#2 diogo

diogo

    Hero Member

  • Moderators
  • 2,068 posts
  • 1179

  • LocationPorto, Portugal

Posted 05 May 2012 - 11:22 AM

You can get a random page from an array like this:

$extra = $page->child->getRandom()


#3 Svet

Svet

    Jr. Member

  • Members
  • PipPip
  • 14 posts
  • 3

Posted 05 May 2012 - 11:37 AM

Topic closed. Not to use this forum as a brain dump place,

but since I cannot delete this posting, I am just going to say this:

be careful about reusing the variable names, even outside of the loop, because otherwize you will end up like me, asking stupid questions lol

#4 diogo

diogo

    Hero Member

  • Moderators
  • 2,068 posts
  • 1179

  • LocationPorto, Portugal

Posted 05 May 2012 - 01:30 PM

The $extra wasn't really an extra? ;)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users