Virik
Virik

Reputation: 407

WordPress - Using same file for home and archive

We would like the home (home.php) and archive (archive.php) pages to look the same in our template.

Is it possible to use the same file by adding a code to functions.php or something like that? So that we don't have to keep both updated with the latest code.

Cheers

Upvotes: 1

Views: 142

Answers (1)

user7236046
user7236046

Reputation:

Put the code you want to have in your archive.php file, or the otherway around. Then in the opposite file you want to have as a duplicate, use the get_template_part() function to call the other template.

For example...

archive.php

<div>
    content etc
</div>

home.php

<?php get_template_part( 'archive' ); ?>

Upvotes: 3

Related Questions