Making title page showcase random images

Hi! I’m trying to modify the home page that comes with the starter kit to show a random image from a random album in my photography page.

I’m using the cookbook on random content, and my template looks like this:

<?php snippet('header') ?>

<main>
  <?php snippet('intro') ?>


  <?php
  $randomImage = page('photography')->children()->shuffle()->first()->images()->shuffle()->first();
 ?>

</main>

<?php snippet('footer') ?>

However, my home page is blank… Sorry, I’m a bit of a noob with PHP (and HTML for that matter), but I can’t see why.

Thanks for your help,

Max

You only define a variable but then you don’t do anything with it. You have to either echo it

<?php
if ($randomImage = page('photography')->children()->shuffle()->first()->images()->shuffle()->first();) {
  echo $randomImage;
}

Or create a tag with the image Url as src attribute.

1 Like

God damn! I fiddled with that a bit and got it working. Thanks a bunch!