Random image URL

Im trying to have a random image show up on my homepage, but i want it to link to the actual image page it is contained on but it keeps reloading the page here is the code:

<?php $counter = 1;
while (next_album() and $counter == 1): ?>
" title="<?php echo getAnnotatedAlbumTitle();?>">
<?php makeImageCurrent(getRandomImages()); printDefaultSizedImage(getImageTitle());?>

<?php $counter++;
endwhile; ?>

Comments

  • What is the while loop for? As coded it only loops once, so seems somewhat redundant.

    Also, your code must not be complete--as shown above there are some dangling constructs. To show code on this forum you should enclose it in 'peck' marks. (On a US PC keyboard that is the character below the tilda on the left end of the numeric key row.)

    Anyway, somewhere there would need to be the href link to the image page.
  • Im still getting to grips with php, i removed the loop now, but it still goes to the same album everytime, how do i set it, so that when i click on the random image it takes me to the (random generated image) page

    `<?php next_album() ?>`
    `" title="<?php echo getAnnotatedAlbumTitle();?>">`
    `<?php makeImageCurrent(getRandomImages()); printDefaultSizedImage(getImageTitle());?>
    `
  • Alright, I was doing something similar today, and here's what I came up with:

    `<?php $randomImage = getRandomImages(); echo '<a href="'.htmlspecialchars(getURL($randomImage)).'" title="'.gettext('Random picture...').'">imagegetSizedImage(getOption('image_size')) ).'" alt=."'.htmlspecialchars($randomImage->getTitle(), ENT_QUOTES).'" />';?>`

    This should leave a default sized random image linking to it's regular image page. Hope that helps!
  • acrylian Administrator, Developer
    You also could have just looked at the existing `printRandomImages()` and could have adapted it since it does not have any size parameters. But it's a good idea, I will add them.
  • yeah great that works fine now! appreciate
Sign In or Register to comment.