V
villabull
Ni
Verificación en dos pasos activada
<?php
$imagenes = array('imagen.gif', 'imagen2.gif', 'imagen3.gif');
shuffle($imagenes);
foreach($imagenes as $imagen){ ?>
<img src="<?=$imagen?>">
<? } ?>
<div id="imagenes"></div>
<script>
var imagenes_array = null;
var imagenes = '';
imagenes_array = [
'imagen1.jpg',
'imagen2.jpg',
'imagen3.jpg',
'imagen4.jpg',
'imagen5.jpg',
'imagen6.jpg'
];
// http://jsfromhell.com/array/shuffle
shuffle = function(v)
{
for(var j, x, i = v.length; i; j = parseInt(Math.random() * i), x = v[--i], v[i] = v[j], v[j] = x);
return v;
};
imagenes_array = shuffle(imagenes_array);
for(var i=0; i<imagenes_array.length; i++) imagenes += '<img src="'+ imagenes_array[i] +'" />';
document.getElementById('imagenes').innerHTML = imagenes;
</script>
PHP:<?php $imagenes = array('imagen.gif', 'imagen2.gif', 'imagen3.gif'); shuffle($imagenes); foreach($imagenes as $imagen){ ?> <img src="<?=$imagen?>"> <? } ?>
Aunque lo haría como respondio zcriptz, también puedes hacerlo con Javascript
Insertar CODE, HTML o PHP:<div id="imagenes"></div> <script> var imagenes_array = null; var imagenes = ''; imagenes_array = [ 'imagen1.jpg', 'imagen2.jpg', 'imagen3.jpg', 'imagen4.jpg', 'imagen5.jpg', 'imagen6.jpg' ]; // http://jsfromhell.com/array/shuffle shuffle = function(v) { for(var j, x, i = v.length; i; j = parseInt(Math.random() * i), x = v[--i], v[i] = v[j], v[j] = x); return v; }; imagenes_array = shuffle(imagenes_array); for(var i=0; i<imagenes_array.length; i++) imagenes += '<img src="'+ imagenes_array[i] +'" />'; document.getElementById('imagenes').innerHTML = imagenes; </script>
<div id="imagenes"></div>
<script>
var imagenes_array = null;
var imagenes = '';
[B][COLOR="#FF0000"]var imagenes_array = [
['mi_enlace1.html', 'imagen1.jpg'],
['mi_enlace2.html', 'imagen2.jpg'],
['mi_enlace3.html', 'imagen3.jpg'],
['mi_enlace4.html', 'imagen4.jpg'],
['mi_enlace5.html', 'imagen5.jpg'],
['mi_enlace6.html', 'imagen6.jpg']
];[/COLOR][/B]
// http://jsfromhell.com/array/shuffle
shuffle = function(v)
{
for(var j, x, i = v.length; i; j = parseInt(Math.random() * i), x = v[--i], v[i] = v[j], v[j] = x);
return v;
};
imagenes_array = shuffle(imagenes_array);
for(var i=0; i<imagenes_array.length; i++) imagenes += [B][COLOR="#FF0000"]'<a href="' + imagenes_array[i][0] + '"><img src="'+ imagenes_array[i][1] +'" /></a>';[/COLOR][/B]
document.getElementById('imagenes').innerHTML = imagenes;
</script>
Gracias, si quiero agregar más en el código html tengo que poner "," o ";" o simplemente una tras otra sin dividirlas?Con permiso de hugo1, ya que voy a reutilizar su código, te respondo:
Un saludo.
😉
Te recomiendo con PHP sino Google no indexará esas paginas :encouragement:
Gracias zcriptz, como se haría en php agregando el link a las imagenes?
<a href="link.php?imagen=<?=$imagen?>"><img src="<?=$imagen?>"></a>
Solo lo agregas...
Por ejemplo:PHP:<a rel="nofollow" href="link.php?imagen=<?=$imagen?>"><img src="<?=$imagen?>"></a>
Pero si el link es hacia una pagina no hacia la imagen?
Disculpa si molesto tanto.
<div id="imagenes"></div>
<script>
var num = [];
var numeroInicial = 1;
var numeroFinal = 6;
while(numeroInicial <= numeroFinal)
{
num[num.length]= numeroInicial;
numeroInicial++;
}
function shuffle(o)
{
for(var j, x, i = o.length; i; j = Math.floor(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
return o;
}
var html = '';
num = shuffle(num);
num.forEach(function(i) {
html += '<a href="http://www.algo.com"><img src="imagen' + i + '" alt="Título"></a>';
});
document.getElementById('imagenes').innerHTML = html;
</script>
<?php
$num = range(1, 6);
shuffle($num);
foreach ($num as $i) //Cambia el 6 por el número de foto si algún día necesitas
{
echo '<a href="http://www.algo.com"><img src="imagen' . $i . '" alt="Título"></a>';
}
?>
Puedes hacerlo con JavaScript (no es necesario instalar nada, es decir, no es nada externo al navegador):
Insertar CODE, HTML o PHP:<div id="imagenes"></div> <script> var num = []; var numeroInicial = 1; var numeroFinal = 6; while(numeroInicial <= numeroFinal) { num[num.length]= numeroInicial; numeroInicial++; } function shuffle(o) { for(var j, x, i = o.length; i; j = Math.floor(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x); return o; } var html = ''; num = shuffle(num); num.forEach(function(i) { html += '<a rel="nofollow" href="http://www.algo.com"><img src="imagen' + i + '" alt="Título"></a>'; }); document.getElementById('imagenes').innerHTML = html; </script>
O si no, puedes hacerlo con PHP:
PHP:<?php $num = range(1, 6); shuffle($num); foreach ($num as $i) //Cambia el 6 por el número de foto si algún día necesitas { echo '<a rel="nofollow" href="http://www.algo.com"><img src="imagen' . $i . '" alt="Título"></a>'; } ?>
{
echo '<a rel="nofollow" href="http://www.algo.com"><img src="imagen' . $i . '" alt="Título"></a>';
'<a rel="nofollow" href="http://www.algo.com"><img src="imagen' . $i . '" alt="Título"></a>';
'<a rel="nofollow" href="http://www.algo.com"><img src="imagen' . $i . '" alt="Título"></a>';
}
Utilizamos cookies y tecnologías similares para los siguientes fines:
¿Aceptas las cookies y estas tecnologías?
Utilizamos cookies y tecnologías similares para los siguientes fines:
¿Aceptas las cookies y estas tecnologías?