Php隐藏内容,如果它是空的(Wordpress)

时间:2016-08-09 08:06:29

标签: php wordpress

如果值为空,我无法理解如何显示我的内容。 我会解释一下。我有下一个循环:

<?php $loop = new WP_Query( array( 'post_type' => 'name', 'filter' => '1', 'orderby' => 'post_id', 'order' => 'ASC' ) ); ?>

<?php while( $loop->have_posts() ) : $loop->the_post(); ?>

<div class="example"> abc </div>
<?php endwhile; wp_reset_query(); ?>

如果'过滤器'值='1',我想显示 abc 如果{{我>我不想显示 <div class="example"> abc </div> 1}}

如何解决我的问题?提前谢谢!

2 个答案:

答案 0 :(得分:1)

试试这个

<?php if ($filter_value == 1): ?>
<div class="example"> abc </div>
<?php endif; ?>

在上面的代码中<div class="example"> abc </div>仅在filter_value==1为真时显示

答案 1 :(得分:1)

<?php 

$array = array( 'post_type' => 'name', 'filter' => '1', 'orderby' => 'post_id', 'order' => 'ASC' );

$loop = new WP_Query( $array ); ?>

<?php while( $loop->have_posts() ) : $loop->the_post(); ?>

<?php if ($array['filter'] == 1): ?>
<div class="example"> abc </div>
<?php endif; ?> <?php endwhile; wp_reset_query(); ?>

试试这个。编辑。我忘记了最后的 reset_query();