我正在使用 Wordpress 主题,并想让它自动更改背景图片。因此,我使用了一些 PHP 代码并尝试将其构建到网站中,但有些东西不起作用而且我无法弄清楚,因为我对 PHP 不是很好。
函数.php:
<?php
$bilder = glob( "images/*.jpg" );
shuffle( $bilder );
$zufall = imagecreatefromjpeg($bilder[0]);
imagejpeg($zufall);
?>
... 只需在我的 Wordpress 的 CSS 中:
body {
background: url('<?php print $zufall ?>') no-repeat center center fixed;
}
但出于某种原因,它只是不显示图片,我现在真的不了解我的智慧了。 :(
你能帮我或告诉我错误吗?
非常感谢您。
最佳答案
这应该可行——您只需要 $bilder 数组中的图像文件名
函数.php:
<?php
$bilder = glob( "images/*.jpg" );
shuffle( $bilder );
$zufall = $bilder[0];
?>
CSS:
body {
background: url('image/<?php print $zufall ?>') no-repeat center center fixed;
}
关于php - 在 Wordpress 主题中更改背景图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18661370/