6

My understanding from reading the WP template hierachy was that when I set my a page as my posts page in settings > reading settings that Wordpress should use archive.php. Instead it uses index.php.

Obviously I could just put my code in index.php and my site will work. But it doesn't seem like best practice, and I can't find any documentation of best (or good) practice.

Why doesn't Wordpress use archive.php in this circumstance?

And would using index.php as my posts page have unintended consequences?

Note: I've been using the _s theme as a base, but I've had the same problem with no theme base or parent.

3
  • Did you set a specific page as your front page or a list of recent posts? Commented Dec 7, 2017 at 8:19
  • Yes, I always use a static front page. Does that have an impact? Commented Dec 7, 2017 at 8:28
  • Yes. archive.php is for listing the archives, not for a single entry. Use single.php (for posts) or page.php (for pages) or single-$posttype.php (for custom post types). You're looking for the Singular Page tree in the template hierarchy. Commented Dec 7, 2017 at 8:33

2 Answers 2

8

you want to use home.php instead of archive.php as it is blog posts index page (set in WordPress Settings -> Reading). It is also in hierarchy on the third position from bottom.

Sign up to request clarification or add additional context in comments.

2 Comments

Cool thanks, that kind of makes sense, because in old school wordpress your most recent posts would've been your home page.
Further to this you can see the template hierarchy visually here. Look at Blog Posts Index Page as opposed to Archive Page.
2

I was in a similar situation for last 2/3 hours and by changing "Permalink Settings" to "post Name" in wordpress dashboard solved the problem for me.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.