【问题标题】:If statement to hide a <Div>If 语句隐藏 <Div>
【发布时间】:2020-04-07 05:53:34
【问题描述】:

我正在从 Wordpress 的自定义字段中提取“book_series”和“series_link”。

当包含名称和 URL 时,链接会正确显示,但它会在空白页面(不包括链接或系列)上显示“图书系列:”。当留空时如何隐藏内容?

这是我目前所拥有的:

<?php if (('books_series') == true) : ?>
              <div class="series"><b>Book Series: </b><a href="<?php the_field( 'series_link' ); ?>" target="_blank"><?php the_field( 'books_series' ); ?></a></div>
            <?php else: ?>
              <div class="series" hidden></div>
            <?php endif; ?>

谢谢。

【问题讨论】:

    标签: php html wordpress if-statement hide


    【解决方案1】:

    也许,

    if (('books_series') == true)
    

    应该是:

    if (the_field('books_series') == true)
    

    【讨论】:

    • 我试过了,但它基本上输出了两次该字段。我真的不确定这里有什么问题。
    【解决方案2】:

    这是我想出的,它似乎工作,虽然我不确定它的整体功能如何 - `

          <?php if ($series_link) { ?>
                <div class="series"><b>Book Series: </b><a href="<?php the_field( 'series_link' ); ?>" target="_blank"><?php the_field( 'books_series' ); ?></a></div>
          <?php } ?>`
    

    感谢大家的帮助和建议。

    【讨论】:

      猜你喜欢
      • 2021-05-25
      • 1970-01-01
      • 2017-02-05
      • 2014-10-16
      • 1970-01-01
      • 1970-01-01
      • 2014-05-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多