I want to make a custom page that looks exactly the same as index.php, while showing different content.

Right now, on index.php I'm showing only posts under the "News" category, but on my custom page I want to show posts under the "Blog" category.

I tried copy-pasting index.php code into customtemplate.php but it's not working.

Hope you can help me. Thanks in advance!


Need more info please.

You can copy and rename the file something like page-template.php and add a page template header.

//* Template Name: Your Page Template Name


You could rename the file home.php and pre_get_posts to control which category of posts it displays:

function my_home_category( $query ) {
    if ( $query->is_home() && $query->is_main_query() ) {
        $query->set( 'cat', '123' );
add_action( 'pre_get_posts', 'my_home_category' );

It depends on how the loop is generated in your theme.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.