• I’m having trouble perfecting this code to only show the latest blog posts if there are any published. But right now, it’s showing the container blank—blank is correct, but I don’t want the container to even display if there are no blog posts. Not sure where I’m going wrong with this code:

    <?php if ( have_posts() ) {	while ( have_posts() ) { the_post(); ?>
    		<?php if ( in_category( '4' ) ) : ?>
                <div id="bloglatest">
                 <div class="container">
                   	<?php
    
                     $postslist = get_posts('numberposts=3&order=DESC&orderby=date');
    
                     foreach ($postslist as $post) :
    
                     setup_postdata($post);
    
                    ?>
                 <div class="bloglatest col-lg-4 col-md-4 col-sm-6 col-xs-12">
    
                 	<span class="date"><?php the_time(get_option('date_format')) ?></span>
    
                 	<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
    
                         <?php
    						 if ( has_post_thumbnail() ) {
    						 the_post_thumbnail();
    						 }
    						 the_excerpt(); ?>
                    <p class="readmore"><a href="<?php echo get_permalink($recent_post["ID"]); ?>">Continue Reading</a></p>
    
                 </div>
                 <?php endforeach; ?>
            </div>
         </div>
      <?php endif; ?>
  • The topic ‘There are Blogs, Display Container; Otherwise Don't Display Container’ is closed to new replies.