ACF插件关系字段,如果导航标签中没有值,则要隐藏标签

时间:2017-09-11 20:45:29

标签: wordpress advanced-custom-fields

我在我的wp主题中使用bootstrap nav选项卡和acf自定义字段。如果关系中没有值,我想隐藏导航选项卡。怎么做?以下是我的代码 - 我想隐藏兼容选项卡,如果关系不返回任何值

<!-- Nav tabs -->
    <ul class="nav nav-tabs nav-justified" role="tablist">
    <li role="presentation" class="active"><a href="#home" aria-controls="overview" role="tab" data-toggle="tab">Overview</a></li>
    <li role="presentation"><a href="#compatibility" aria-controls="compatibility" role="tab" data-toggle="tab"> Compatibility </a></li>
    <li role="presentation"><a href="#datasheet" aria-controls="datasheet" role="tab" data-toggle="tab">Datasheet</a></li>
    <li role="presentation"><a href="#order" aria-controls="order" role="tab" data-toggle="tab">Order</a></li>
    </ul>

    <!-- Tab panes -->
    <div class="tab-content">
        <div role="tabpanel" class="tab-pane fade in active" id="home">
            <div role="tabpanel" class="tab-pane fade" id="compatibility">
                <?php
                  $posts = get_field('compatible_with');
                  if( $posts ): ?>
                    <ul>
                    <?php foreach( $posts as $p ): // variable must NOT be called $post (IMPORTANT) ?>
                    <li>
                    <a href="<?php echo get_permalink( $p->ID ); ?>" rel="</a>
                    <a href="<?php echo get_permalink( $p->ID ); ?>"><?php echo get_the_title( $p->ID ); ?></a>
                    </li>
                    <?php endforeach; ?>
                </ul>
            <?php endif; ?>

            </div>
            <div role="tabpanel" class="tab-pane fade" id="datasheet"></div>
            <div role="tabpanel" class="tab-pane fade" id="order"></div>
                                </div>
                             </div>
                          </div>
                     </div>
                 </div>

我想使用此功能

if( count( get_field('compatible_with') ) > 0 ) :

1 个答案:

答案 0 :(得分:0)

任何方式只使用这两行代码,我解决了问题

<?php if( get_field('compatible_with') ): ?>
<li role="presentation"><a href="#compatibility" aria-controls="compatibility" role="tab" data-toggle="tab"> Compatibility </a></li>    
<?php endif; ?>