WordPress: define another page as the homepage

WordPress: define another page as the homepage

You want to display another page of your WordPress blog just like the original homepage without plugins? No problem!

First you need to create a new template based on the old homepage template (index.php or home.php).

We could name this file newhome.php for example.

To be able to use the file later we assign a name to the file:

 /*
    Template Name: newhome
    */

After that we add the following in the upper php section directly under “get_header();”:

$blog_posts = new WP_Query( array( 'post_type' => 'post', 'post_status'' => 'publish', 'posts_per_page' => -1 ) );

After that we move on to find the while loop, it looks something like this:

<?php while ( have_posts() ) : the_post(); ?>

We now modify this loop as follows:

<?php while ( $blog_posts->have_posts() ) : $blog_posts->the_post(); ?>

As soon as we create a new page we can select “newhome” as template and have our new homepage under a different URL.

Leave a Reply

Your email address will not be published. Required fields are marked *