I am trying to put a Random Image on the top of the post, If I do the following code it shows all three images and link which is aspected. see it in here PALEOALL.
How could I randomise it to show just it one of then at time randomly with the php while command is running?
<?php while ( have_posts() ) : the_post(); ?>
<?php
get_template_part( 'content', get_post_format() );
?>
<a href="http://ift.tt/1KNqQVN" title="Your Guide to Paleo"><img src="http://ift.tt/1g3J8V3" width="468" height="60" alt="Your Guide to Paleo" style="border: 1px solid #cccccc;" /></a>
<a href="http://ift.tt/1KNqQVN" title="Your Guide to Paleo"><img src="http://ift.tt/1KNqRZG" width="468" height="60" alt="Your Guide to Paleo" style="border: 1px solid #cccccc;" /></a>
<a href="http://ift.tt/1KNqQVN" title="Your Guide to Paleo"><img src="http://ift.tt/1g3J6N1" width="468" height="60" alt="Your Guide to Paleo" style="border: 1px solid #cccccc;" /></a>
<?php endwhile; ?>
I tried this but is not working with the while.
<?php
$images = array(
array("src" => "img src="http://ift.tt/1g3J8V3", "url" => "http://ift.tt/1KNqQVN"),
array("src" => "img src="http://ift.tt/1KNqRZG", "url" => "http://ift.tt/1KNqQVN"),
array("src" => "img src="http://ift.tt/1g3J6N1", "url" => "http://ift.tt/1KNqQVN"),
array("src" => "img src="http://ift.tt/1KNqTRa", "url" => "http://ift.tt/1KNqQVN"),
array("src" => "img src="http://ift.tt/1g3J8V7", "url" => "http://ift.tt/1KNqQVN")
);
shuffle($images);
echo '<div class="images">';
foreach ($images as $image) {
echo '<a href="'.$image["url"].'"><img src="'.$image["src"].'" /></a>';
}
echo '</div>';
Thank You in Advance.
Aucun commentaire:
Enregistrer un commentaire