php - 在 Wordpress 主题中更改背景图片

标签 php css image wordpress background

我正在使用 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/

相关文章:

python - 在 Python 中使用 OpenCV 旋转图像时指定背景颜色

jquery - 图像大小(响应 slider )

html - 制作一个响应式按钮,使其保持在图像顶部的相同位置

image - 如何识别NSData的图像格式?

php - 显示每个类别最新帖子的下拉导航菜单

php - jQuery 不会在 .load() 回调中的 .ajax() 完成之前执行 .load() 吗?

php - WordPress:多站点帖子查询的过滤器类别

php - 在 PHP 中覆盖扩展类中的命名空间使用

javascript - CSS 和 Javascript 优化(速度问题)

html - IE 8 兼容模式导致表单提交按钮换行