Reputation: 185
I'd like to know if there's a way to make a certain div display:none when there's no post.
Here's what I came up with so far:
<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>
What I'd like to know is if there's a way to make the MVP-box div disappear when there's no post content. Any ideas?
Upvotes: 0
Views: 199
Reputation: 2967
Can you just check have_posts before you draw the div?
<?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 } ?>
Upvotes: 3