How to show single post page as home page

I want to start a funny images website but I have come across a dilemma. I want the website to display 1 post ( not the thumbnail) but the full post on the home page. (the most recent post). Similar to jokideo can anyone please direct me to a theme or provide some code that I need to edit in the wp theme files.

Thanks 🙂

Related posts

Leave a Reply

3 comments

  1. It depends on what theme you use as they are not coded the same.

    Use pre_get_posts or the reading settings and the_content() rather than the_excerpt() in your loop.

    function wpsites_home_page_limit( $query ) {
        if ( $query->is_home() && $query->is_main_query() && !is_admin() ) {
            $query->set( 'posts_per_page', '1' );
        }
    }
    add_action( 'pre_get_posts', 'wpsites_home_page_limit' );
    

    Or you could redirect the latest single post to display on the home page.

  2. Create a page template with this code between header and footer:

    <?php
    /**
     * Template Name: The Last Post
     * 
     */
    get_header();
    
    //The code begins here
    
    $the_query = new WP_Query( 'posts_per_page=1' ); 
    
    while ($the_query -> have_posts()) : $the_query -> the_post(); ?>
        <a href="<?php the_permalink() ?>"><?php the_title(); ?></a>
        <?php the_content();
    endwhile;
    
    //The code ends here
    
    get_footer(); ?>
    

    Then create a new page, select this template and save it. Now in Settings > Reading, select the option “static page” and define the page created as “Front page”.

    Also, create a new white page with the blog name —for example— and save it. In Settings > Reading, define this page as “Posts page”. Now we have the last post in the front page and all the posts in a blog page.

    But we still need to exclude the last post in the loop, in order to avoid duplicate content. You will probably find the loop in the file index.php or loop.php.

    Find this line:

    if ( have_posts() ) : while ( have_posts() ) : the_post();
    

    And add these lines overriding the last one:

    $offset = new WP_Query( 'offset=1' ); 
    if ( have_posts() ) : while ($offset -> have_posts() ) : $offset -> the_post();
    
  3. I would recommend altering the loop that displays the home page posts. Something like

    <?php /* Start the Loop */ 
            $i=0; 
            while ( have_posts() ) {
    
                the_post();
    
                if($i === 0){
                    get_template_part( 'content', get_post_format() );
                    break;
                }
                $i++;
            }
    ?>
    

    There probably are better and more elegant solutions to this, but this is quite simple to implement.

    You can edit the file responsible for displaying front page posts (index.php in the twentytwelve theme ), but I wouldn’t recommend this seeing that it might be overwritten when updating. It will be better to use a custom theme, maybe a child theme, or to use a custom template file for the front page