【问题标题】:Changing background images in Wordpress theme更改 Wordpress 主题中的背景图像
【发布时间】:2013-09-06 23:41:36
【问题描述】:

我正在使用 Wordpress 主题,并希望让它自动更改背景图像。因此,我使用了一些 PHP 代码并尝试将其构建到网站中,但有些东西不起作用,我无法弄清楚,因为我对 PHP 不是很好。

functions.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;
}

但由于某种原因,它只是没有显示图片,我现在真的不了解我的智慧了。 :(

你能帮我或告诉我错误吗?

非常感谢您。

【问题讨论】:

    标签: php css image wordpress background


    【解决方案1】:

    这应该可以 - 你只需要 $bilder 数组中的图像文件名

    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;
    }
    

    【讨论】:

    • 不幸的是,这没有帮助。我感觉 Wordpress 主题中的 functions.php 是放置 PHP 代码的错误文件,但我对 Wordpress 或在哪里放置自定义 PHP 内容一无所知。如果有帮助,我可以说明我现在遇到问题的网站。
    • 我刚刚回来查看。显然,functions.php 文件是放置自定义 PHP 代码的正确文件。 :) 所以,事实并非如此。 :\
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-11-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-25
    相关资源
    最近更新 更多