PHP回声分类法 /隐藏如果术语为空(WordPress)



我创建了一个我使用echo来调用的自定义分类法(WordPress)。仅在该术语具有值时,我才只能在其中称其为?(隐藏空)

我的代码:

<div class="storleken"><span class="sku_wrapper">
<span class="sku" itemprop="sku">
<?php echo get_the_term_list( get_the_ID(), 'storlek' ); ?>
</span></span></div>

尝试以下:

<?php 
    $term_list = get_the_term_list( get_the_ID(), 'storlek' );
    if(!empty($term_list)):
?>
<div class="storleken">
    <span class="sku_wrapper">
        <span class="sku" itemprop="sku">   
            <?php 
                echo $term_list; 
            ?>
        </span>
    </span>
</div>
<?php
    endif;
?>

在这里,我已将术语列表分配给一个称为$term_list的变量,之后,我正在检查它是否为空的PHP函数为空。

最新更新