wp_query latest post (4 posts)

  1. ByronCooke
    Posted 3 years ago #

    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

            $latest_post = new WP_Query("showposts=1");
            if($latest_post->have_post()) :
        <div class="boxBar">
            <h1 class="boxedHeader">
                <?php the_title() ?>
            <?php endwhile ?>
        <?php endif ?>
  2. Michael
    Forum Moderator
    Posted 3 years ago #

    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");
  3. ByronCooke
    Posted 3 years ago #

    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

  4. ByronCooke
    Posted 3 years ago #

    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

Topic Closed

This topic has been closed to new replies.

About this Topic