WordPress.org

Support

Support » Plugins and Hacks » Hacks » wp_query latest post

wp_query latest post

  • I have been attempting to display my latest post on the home page of my site but I cant understand why my code wont work? can anyone help?

    Thanks, Byron

    <?php
            $latest_post = new WP_Query("showposts=1");
            if($latest_post->have_post()) :
        ?>
        <div class="boxBar">
            <?php
                while($latest_post->have_post()):
                    $latest_post->the_post();
            ?>
            <h1 class="boxedHeader">
                <?php the_title() ?>
            </h1>
            <?php endwhile ?>
        </div>
        <?php endif ?>
Viewing 3 replies - 1 through 3 (of 3 total)
  • what exactly happens with the ‘wont work’?
    i.e. what is the result?

    see all parameters for WP_Query() http://codex.wordpress.org/Class_Reference/WP_Query#Parameters

    possibly try:

    $latest_post = new WP_Query("post_type=post&posts_per_page=1&orderby=date&order=DESC");

    thanks for the reply, that still didnt get it working unfortunately

    the problem is the title isnt being displayed, neither is the div ‘boxBar’ and all content after, without the php all html elements display ok

    oh my god, I cant believe how simple the problem was, i missed the s off the end of have_posts()

    think its too late, time for bed haha

    thanks anyway for your time

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘wp_query latest post’ is closed to new replies.
Skip to toolbar