自定义领域背景后备图像

时间:2016-01-11 12:43:34

标签: php wordpress custom-fields advanced-custom-fields

我正在使用自定义字段在我的wordpress博客的每个页面上显示不同的背景,如下所示:

<div id="wrapper" style="background-image: url('<?php the_field('background'); ?>');">

但是现在我想要一个后备图像,因为它们没有设置图像。

有人知道怎么做吗?

提前thnx

1 个答案:

答案 0 :(得分:0)

我假设你的代码在循环中

<?php if(isset(get_field('background'))){?>
<div id="wrapper" style="background-image: url('<?php the_field('background'); ?>');
<?php } else{?>
<div id="wrapper" style="background-image: url('any_custom_image_path');

<?php }?>
相关问题