php 将后缩略图作为背景图像添加到任何div
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 将后缩略图作为背景图像添加到任何div相关的知识,希望对你有一定的参考价值。
<?php
add_action( 'wp_head', 'vr_set_featured_background', 99);
function vr_set_featured_background() {
$image_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), full, false );
if ($image_url[0]) {
?>
<style>
#single-post-heading-bg {
background:linear-gradient(rgba(0, 0, 0, 0.35), rgba(0, 0, 0, 0.35)), rgba(0,0,0,0.35) url(<?php echo $image_url[0]; ?>) no-repeat center;
background-size: cover;
padding: 100px 0;
}
#single-post-heading-bg h1,
#single-post-heading-bg p {
color: #fff;
}
/* Uncomment if the image hangs low in a Genesis theme */
/*.site-inner {
padding-top:0!important;
padding-bottom:0!important;
}*/
</style>
<?php
}
}
?>
以上是关于php 将后缩略图作为背景图像添加到任何div的主要内容,如果未能解决你的问题,请参考以下文章