Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wordpress 当ACF字段为空时隐藏它们_Wordpress_Advanced Custom Fields - Fatal编程技术网

Wordpress 当ACF字段为空时隐藏它们

Wordpress 当ACF字段为空时隐藏它们,wordpress,advanced-custom-fields,Wordpress,Advanced Custom Fields,我将以下代码用于带有自定义字段的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 te

我将以下代码用于带有自定义字段的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'))我试图在自定义字段为空但不起作用时隐藏它。我怎么能把它藏起来

致意

克里斯

补编: 特殊产品的输出(当自定义字段为空时)为:

数组([image]=>[description]=>[product link]=>[thumb1]=>[thumb2]=>[thumb3]=>)

当运行print\r($special\u product)时,您得到:

由于empty字段返回一个空数组,而不是一无所有,因此它永远不能被视为空,您需要检查数组中的键,以查看keys值是否为空

我让它检查数组的图像字段,看看它是否为空

如果您的产品不总是有图像,那么可以随意更改它,以检查始终存在的字段

这是您的工作代码:

// vars
$special_product = get_field('special_product', $term); 

<?php if ( $special_product['image'] ): ?>
    <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> <!--close container -->
    </div>   <!--close container_wrap --> 
<?php endif; ?>
//变量
$special\u product=get\u字段($special\u product',$term);
运行print\r($special\u product)时,您会得到:

由于empty字段返回一个空数组,而不是一无所有,因此它永远不能被视为空,您需要检查数组中的键,以查看keys值是否为空

我让它检查数组的图像字段,看看它是否为空

如果您的产品不总是有图像,那么可以随意更改它,以检查始终存在的字段

这是您的工作代码:

// vars
$special_product = get_field('special_product', $term); 

<?php if ( $special_product['image'] ): ?>
    <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> <!--close container -->
    </div>   <!--close container_wrap --> 
<?php endif; ?>
//变量
$special\u product=get\u字段($special\u product',$term);

这就是它通过文档工作的方式,因此您的get\u字段不能正常工作,如果您使用\u字段,它是否会执行值,因为您的$term可能不工作mh。。好啊我不知道如何修理它。字段始终显示(im为空或不为空)。仅当我在开头使用此字段时,才会显示自定义字段:
$special\u product=get\u字段('special\u product',$term);如果(get_field('special_product',$term)):?>更新的答案,以及special_product的字段类型是什么?这是使用的代码。。。但当自定义字段为空时,它也会显示所有div容器:-(这是通过文档工作的方式,因此get_字段一定不能正常工作,如果使用_字段,它是否会执行值,因为$term可能不工作…。好的!我不知道如何修复它。字段总是显示(我是空的还是不空的)自定义字段仅在我开始使用时显示:
$special\u product=get\u字段('special\u product',$term);if(get\u字段('special\u product',$term)):?>更新的答案,以及special\u product的字段类型是什么?这是使用的代码…但当自定义字段为空时,它也显示所有div容器:-(