Reputation: 127
I am using a Wordpress theme and want to make it change the background images automatically. So, I used some PHP code and tried to build it into the website, but something is not working and I cannot figure it out, as I am not very good with PHP.
functions.php:
<?php
$bilder = glob( "images/*.jpg" );
shuffle( $bilder );
$zufall = imagecreatefromjpeg($bilder[0]);
imagejpeg($zufall);
?>
... and simply in CSS of my Wordpress:
body {
background: url('<?php print $zufall ?>') no-repeat center center fixed;
}
But for some reason it just does not show the pictures and I am really off with my wisdom now. :(
Can you help me or tell me the error?
Thank you very much in advance.
Upvotes: 0
Views: 743
Reputation: 3073
This should work - you just need the filename of the image which is in the $bilder array
functions.php:
<?php
$bilder = glob( "images/*.jpg" );
shuffle( $bilder );
$zufall = $bilder[0];
?>
CSS:
body {
background: url('image/<?php print $zufall ?>') no-repeat center center fixed;
}
Upvotes: 1