mercredi 19 février 2020

Randomly show image + link in html newsletter template

Let's say i have a list of 4 images and i'm trying to randomly show 2 of them each time the newsletter is loaded.

I have a file show_image.php with the following array:

$images = array(
  0 => array(
    'image' => 'http://example.com/img/partner1.jpg'
    'link' => 'http://www.example1.com'
  ),
  1 => array(
    'image' => 'http://example.com/img/partner2.jpg'
    'link' => 'http://www.example2.com'
  ),
  2 => array(
    'image' => 'http://example.com/img/partner3.jpg'
    'link' => 'http://www.example3.com'
  ),
  3 => array(
    'image' => 'http://example.com/img/partner4.jpg'
    'link' => 'http://www.example4.com'
  )
);

In my current situation, the images in the (html) newsletter template look like this:

<a href="http://example.com/show_image.php?zone=1&field=link">
  <img src="http://example.com/show_image.php?zone=1&field=image">
</a>
<a href="http://example.com/show_image.php?zone=2&field=link">
  <img src="http://example.com/show_image.php?zone=2&field=image">
</a>

As you can see, the call for a random image and link are separate, causing the php script to respond with a random link that doesn't match the random image.

Can anyone point me in the right direction how to randomly show an image with the right corresponding link?




Aucun commentaire:

Enregistrer un commentaire