Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I would like to display the most recent post in a block, and if the post is assigned with a thumbnail I would like it to be shown on the left to the post content.

This is my code that I have been trying

                <?php query_posts('posts_per_page=1') ?>
            <?php while ( have_posts() ) : the_post(); ?>

                <div class="jumbotron">
                    <?php if ( has_post_thumbnail(); )?>
                    <div class="col-md-3">
                        <?php the_post_thumbnail(); ?>
                    </div>
                    <div class="col-md-9">
                        <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
                        <p><?php the_excerpt(); ?></p>
                        <p class="text-muted">Posted on <?php the_time('jS F, Y'); ?></p>
                </div>

                    } 
                <?php else;?>
                    <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
                    <p><?php the_excerpt(); ?></p>
                    <p class="text-muted">Posted on <?php the_time('jS F, Y'); ?></p>
                </div>

            <?php endwhile; wp_reset_query(); ?>
share|improve this question

1 Answer 1

you just need to clean up the if statement:

<?php if ( has_post_thumbnail() ) { ?>
<div class="col-md-3">
    <?php the_post_thumbnail(); ?>
</div>
<?php } ?> 

here's the whole bit cleaned up:

 <?php query_posts('posts_per_page=1') ?>
            <?php while ( have_posts() ) : the_post(); ?>

                <div class="jumbotron">
                    <?php if ( has_post_thumbnail(); { )?>
                    <div class="col-md-3">
                        <?php the_post_thumbnail(); ?>
                    </div>
                    <?php } ?>
                    <div class="col-md-9">
                        <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
                        <p><?php the_excerpt(); ?></p>
                        <p class="text-muted">Posted on <?php the_time('jS F, Y'); ?></p>
                    </div>

                </div>

            <?php endwhile; wp_reset_query(); ?>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.