WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. robinhry
    Member
    Posted 1 year 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.

    Thanks

  2. alchymyth
    The Sweeper & Moderator
    Posted 1 year 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:
    http://codex.wordpress.org/The_Loop
    http://codex.wordpress.org/Class_Reference/WP_Query

    example:

    <?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//
    endwhile;
    echo '</div>';
    endif; wp_reset_postdata(); ?>

Topic Closed

This topic has been closed to new replies.

About this Topic