Ready to get started?Download WordPress


How to display latest post below welcome text at static page (2 posts)

  1. robinhry
    Posted 2 years ago #

    I am running a wordpress blog -http://haryanainfo.in/, I have make a static page for home page for the introduction of website. Now I want to display latest post under the welcome test.

    I don't want to use plugins for this job. Is there any other way for this. Please guide me with some details because I haven't much knowledge of programming.


  2. alchymyth
    Forum Moderator
    Posted 2 years ago #

    create a page template http://codex.wordpress.org/Pages#Page_Templates

    start with a copy of page.php of your theme, then, somewhere after the line with 'the_content();` add a secondary loop with a custom query:


    <?php $latest = new WP_Query( array( 'posts_per_page' => 1, 'post_type' => 'post' ) );
    if( $latest->have_posts() ) :
    echo '<div class="latest-post">';
    while( $latest->have_posts() ) : $lastest->the_post();
    the_title(); //whatever you want to output for that post - possiby pull some code from single.php//
    echo '</div>';
    endif; wp_reset_postdata(); ?>

Topic Closed

This topic has been closed to new replies.

About this Topic