【问题标题】:Custom field background fallback image自定义字段背景后备图片
【发布时间】:2016-04-15 18:46:46
【问题描述】:

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

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

但现在我想要一个 fallback 图像,以便在没有设置图像时使用。

有人知道怎么做吗?

请提前

【问题讨论】:

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


【解决方案1】:

我假设你的代码在循环中

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

【讨论】:

  • &lt;?php if(get_field('background')){?&gt; 也可以。就我个人而言,我喜欢为全局默认值和后备设置一个选项页面,以便用户可以输入自己的后备图像。
猜你喜欢
  • 1970-01-01
  • 2013-10-13
  • 2011-03-24
  • 1970-01-01
  • 1970-01-01
  • 2011-03-15
  • 2018-07-15
  • 2018-06-18
  • 2018-05-11
相关资源
最近更新 更多