我有這段代碼,我正在使用高級自定義欄位。它在帖子型別中,即使欄位沒有鏈接,我也需要顯示影像。即使欄位沒有鏈接,我如何顯示影像?
<div class="link col-lg-4">
<?php
$link = get_field('link_product');
if( $link ):
$link_url = $link['url'];
?>
<a class="button" target="_blank" href="<?php echo esc_url( $link_url ); ?>">
<img src="<?php echo the_post_thumbnail_url();?>" alt="">
</a>
<?php endif;
?>
</div>
圖片
uj5u.com熱心網友回復:
當前影像在 if 中,當鏈接為 false 時,將跳過代碼。
您可以簡單地在 endif 之前添加 else 條件并將影像放在那里。
<?php
else:
?>
<img src="<?php echo the_post_thumbnail_url();?>" alt="">
<?php
endif;
?>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/510086.html
上一篇:根據產品id排列物品
