Imagens linkadas randômicas

Aqui temos um código simples para exibir imagens (que podem ser banners) linkadas de forma aleatória.

PHP:
  1. <?php
  2. /*
  3. Simple randomizer.
  4. Roger Johansson, http://www.456bereastreet.com/
  5. */
  6. echo '<ul>' . "\n";
  7. $items = array(
  8.     1 => array(
  9.         'href' => 'url-1',
  10.         'title' => 'title-text-1',
  11.         'src' => 'image-1.jpg',
  12.         'alt' => 'alt-text-1'
  13.     ),
  14.     2 => array(
  15.         'href' => 'url-2',
  16.         'title' => 'title-text-2',
  17.         'src' => 'image-2.jpg',
  18.         'alt' => 'alt-text-2'
  19.     ),
  20.     3 => array(
  21.         'href' => 'url-3',
  22.         'title' => 'title-text-3',
  23.         'src' => 'image-3.jpg',
  24.         'alt' => 'alt-text-3'
  25.     ),
  26.     4 => array(
  27.         'href' => 'url-4',
  28.         'title' => 'title-text-4',
  29.         'src' => 'image-4.jpg',
  30.         'alt' => 'alt-text-4'
  31.     ),
  32.     5 => array(
  33.         'href' => 'url-5',
  34.         'title' => 'title-text-5',
  35.         'src' => 'image-5.jpg',
  36.         'alt' => 'alt-text-5'
  37.     )
  38. );
  39. $numberOfItems = 3; // Change to the number of items you want
  40. $randItems = array_rand($arrItems, $numberOfItems);
  41. for ($i = 0; $i <$numberOfItems; $i++) {
  42.     $item = $arrItems[$randItems[$i]];
  43.     echo "\t" . '<li class="r' . ($i + 1) . '"><a href="' . $item['href'] . '" title="' . $item['title'] . '"><img src="' . $item['src'] . '" alt="' . $item['alt'] . '"></a></li>' . "\n";
  44. }
  45. echo '</ul>' . "\n";
  46. ?>

Pesquisa personalizada

1 comentário

  1. Teo says:

    rapaz, legal esse script em php…

    vou colocar alguns banner que vai mudar sozinho! valeu
    forte abraço

Deixe seus comentários