【问题标题】:Show code / element if custom field is present如果存在自定义字段,则显示代码/元素
【发布时间】:2014-02-14 11:35:02
【问题描述】:

基本上我正在寻找最简单的代码来解决这个问题。我有一个在为 iframe src 填充自定义字段时填充的 iframe。

基本上,如果未填写自定义字段,我希望 iframe 代码完全消失。

这样我就可以在 page.php 中弹出此代码,并且 iframe 仅显示自定义字段是否已填充。

<?php
    $iframe_src = get_post_meta( get_the_ID(), 'iframe_src', true );
    $iframe_height = get_post_meta( get_the_ID(), 'iframe_height', true );

    $height = ( $iframe_height == "" || !$iframe_height ) ? 2650 : $iframe_height;
?>
<iframe SRC="<?php echo $iframe_src; ?>" WIDTH="100%" HEIGHT="<?php echo $height; ?>" frameborder="0" scrolling="no" name="content"></iframe>

【问题讨论】:

  • if ($iframe_src != '') { ... } ?
  • 对不起,我比较新,我把这个放在哪里?

标签: javascript php iframe if-statement custom-fields


【解决方案1】:

您可以检查 $iframe_src 是否设置为:

<?php 
   if(!empty($iframe_src)) {
       ?><iframe SRC="<?php echo $iframe_src; ?>" WIDTH="100%" HEIGHT="<?php echo $height; ?>" frameborder="0" scrolling="no" name="content"></iframe><?php
   }
?>

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-05-22
  • 1970-01-01
  • 1970-01-01
  • 2013-01-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多