我正在尝试创建一个应该使用特色图像作为背景的帖子,如果没有选择图像,它应该使用背景颜色。
我在这里和谷歌都搜索过,但我只能找到这段代码。
<?php
if (has_post_thumbnail( $post->ID ) ):
$image_attributes = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full' );
else:
$image_attributes = array( '#fa5252; opacity:1!important' );
endif;
?>
<div style="background: url(<?php echo $image_attributes[0]; ?>)"></div>
不用说,它并不完全有效。