我正在从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; ?>
谢谢。
答案 0 :(得分:0)
也许
if (('books_series') == true)
应该是:
if (the_field('books_series') == true)
答案 1 :(得分:0)
这是我想出的,它似乎可以工作,尽管我不确定它的整体功能如何-`
<?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 } ?>`
感谢大家的帮助和建议。