【发布时间】:2019-04-11 13:39:03
【问题描述】:
我将以下代码用于带有自定义字段的 wordpress 模板:
<?php
// vars
$special_product = get_field('special_product', $term);
if (!get_field('special_product') )
if ( $special_product): ?>
<div class="container_wrap container_wrap_first main_color sidebar_right
template-shop">
<div class="container">
<div class="container-left-sp single-product-main-image alpha">
<a class="lightbox-added lightbox avia_image" href="<?php echo $special_product['image']['url']; ?>" rel="lightbox" title="" rel="product_images[grouped]">
<img src="<?php echo $special_product['image']['url']; ?>" alt="<?php echo $special_product['image']['alt']; ?>" /></a>
<div class="thumbnails">
<a class="lightbox-added lightbox avia_image thumb-image" href="<?php echo $special_product['thumb1']['url']; ?>" rel="lightbox" title="" rel="product_images[grouped]">
<img width="100" height="100" src="<?php echo $special_product['thumb1']['url']; ?>" class="attachment-shop_thumbnail size-shop_thumbnail" alt="<?php echo $special_product['thumb1']['alt']; ?>" /></a>
<a class="lightbox-added lightbox avia_image thumb-image" href="<?php echo $special_product['thumb2']['url']; ?>" rel="lightbox" title="" rel="product_images[grouped]">
<img width="100" height="100" src="<?php echo $special_product['thumb2']['url']; ?>" class="attachment-shop_thumbnail size-shop_thumbnail" alt="<?php echo $special_product['thumb2']['alt']; ?>" /></a>
<a class="lightbox-added lightbox avia_image thumb-image" href="<?php echo $special_product['thumb3']['url']; ?>" rel="lightbox" title="" rel="product_images[grouped]">
<img width="100" height="100" src="<?php echo $special_product['thumb3']['url']; ?>" class="attachment-shop_thumbnail size-shop_thumbnail" alt="<?php echo $special_product['thumb3']['alt']; ?>" /></a>
</div>
</div>
<div class="container-right-sp single-product-summary">
<?php echo $special_product['description']; ?>
<a class="avia-slideshow-button avia-button avia-color-orange avia-multi-slideshow-button" href="<?php echo $special_product['product-link']['url']; ?>">
Zum Produkt</a>
</div>
<div>
</div>
</div> <!--close container -->
</div> <!--close container_wrap -->
<?php endif; ?>
使用代码 if (!get_field('special_product') ) 我尝试在自定义字段为空时隐藏它,但它不起作用。怎么隐藏?
最好的问候
克里斯
补充: &special_product 的输出(当自定义字段为空时)是:
数组([图片] => [描述] => [产品链接] => [thumb1] => [thumb2] => [thumb3] => )
【问题讨论】:
标签: wordpress advanced-custom-fields