Imagens linkadas randômicas

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

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


  • -------------------------------------------------------------------------------------

    Postagens Relacionadas
    Anterior
    « Anterior
    Proxima
    Proxima »