Php 如果存在',则使div消失;没有内容

Php 如果存在',则使div消失;没有内容,php,wordpress,Php,Wordpress,我想知道是否有一种方法可以使某个div显示:没有post时为none 以下是我到目前为止的想法: <div class="MVP-box"> <?php $loop = new WP_Query(array('post_type' => 'MVP', 'posts_per_page' => 1)); ?> <?php while ( $loop->have_posts() ) : $loop->t

我想知道是否有一种方法可以使某个div显示:没有post时为none

以下是我到目前为止的想法:

<div class="MVP-box">

    <?php 
        $loop = new WP_Query(array('post_type' => 'MVP', 'posts_per_page' => 1)); 
    ?>
    <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
    <?php   
        $custom = get_post_custom($post->ID);
        $screenshot_url = $custom["screenshot_url"][0];
        $website_url = $custom["website_url"][0];
    ?>


        <div class="post-entry">
        <div class="MVP-title">
        <?php the_title(); ?>
        </div>
        <div class="MVP-thumbnail">
            <?php the_post_thumbnail('MVP-picture'); ?>
        </div>
       <?php the_content(); ?>
        </div>
        <?php endwhile; ?>  

</div>


我想知道的是,如果没有帖子内容,是否有办法让MVP box div消失。有什么想法吗?

在画div之前,你能检查一下have_posts吗

<?php 
  $loop = new WP_Query(array('post_type' => 'MVP', 'posts_per_page' => 1)); 
  if ($loop->have_posts()) { ?>
   <div class="MVP-box">


<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<?php   
    $custom = get_post_custom($post->ID);
    $screenshot_url = $custom["screenshot_url"][0];
    $website_url = $custom["website_url"][0];
?>


    <div class="post-entry">
    <div class="MVP-title">
    <?php the_title(); ?>
    </div>
    <div class="MVP-thumbnail">
        <?php the_post_thumbnail('MVP-picture'); ?>
    </div>
   <?php the_content(); ?>
    </div>
    <?php endwhile; ?>  

</div>
<?php } ?>

在绘制div之前,您能检查一下have_posts吗

<?php 
  $loop = new WP_Query(array('post_type' => 'MVP', 'posts_per_page' => 1)); 
  if ($loop->have_posts()) { ?>
   <div class="MVP-box">


<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<?php   
    $custom = get_post_custom($post->ID);
    $screenshot_url = $custom["screenshot_url"][0];
    $website_url = $custom["website_url"][0];
?>


    <div class="post-entry">
    <div class="MVP-title">
    <?php the_title(); ?>
    </div>
    <div class="MVP-thumbnail">
        <?php the_post_thumbnail('MVP-picture'); ?>
    </div>
   <?php the_content(); ?>
    </div>
    <?php endwhile; ?>  

</div>
<?php } ?>