繁体   English   中英

wordpress博客动态背景图片

[英]wordpress blog dynamic background image

抱歉,如果已经解决了这个问题,但是如果找不到,我很抱歉。

我正在整理一个博客网站,打算将其转换为wordpress主题。 对于每个博客文章,我在登录页面上都有一个全屏图像链接,该链接将为您提供特定的博客文章。 每个帖子的代码是相同的。

的HTML

<a href="#" ><div class="post"></div></a>

的CSS

.post{
    width: 100%;
    height: 75vh; 
    background-image: url(../img/5.jpg); 
    background-position: center 0px; 
    background-repeat: repeat-y; 
    background-attachment: fixed; 
    margin-bottom: 100px; 
    position: relative; 
}

当我希望将其转换为wordpress主题时,我需要一种方法来复制具有与每个新帖子相关的不同背景图像的代码。 他们有办法使用PHP或javascript吗?

是的,您可以为此使用“自定义”字段。 https://codex.wordpress.org/Custom_Fields

<?php
$cust_image = get_post_meta($post->ID, 'backgroundimg', true);
echo '.post {background-image:url(';
echo $cust_image ? $cust_image : '../default_background.jpg';
echo ');}';
?>

希望这对您有用。

<a href="#" >
    <div class="post" style="background-image:url('<?php the_post_thumbnail_url( $post->ID ); ?>')">
    </div>
</a>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM