The difference between archives.php and archive.php
I was recently working on another website and had added an Archives widget to a sidebar on the page for the blog posts. The widget itself was showing the correct dates – only April 2015 currently – but it was displaying properly. However, when I clicked on the April 2015 date from the drop-down menu for the Archives widget, I was being taken to the homepage. I had no idea what was going on as I had an archives.php file for this WordPress template I was working with, and I thought it should have been directly me there. I was wrong.
In doing some searching for this issue, I discovered the problem. The archives.php file is a template for a page that you can create for archives and then you can apply that template to the Archives page. This is good if you have the archives set up as part of your navigation somewhere and can navigate to this page on its own. However, I didn’t have anything like that. What I needed was the archive.php file. These files are very different, even though the difference in file names is only an “s.”
The archive.php file is used to display custom post archives. When this file isn’t present in a WordPress theme, it defaults to the index.php file, which is why when I clicked on the date from the Archives widget drop-down menu it was taking me to my homepage. Once I included the archive.php file and placed the appropriate code within this file to display things the way I wanted, the link for April 2015 archives was working properly and taking me to the appropriate archives page.