I'm writing my own WordPress theme and I'm having problems with the archive page. My archive link yields a 404 Not Found. I get this link from get_post_type_archive_link("post")
and it just adds /archives
to the base URL of my website.
My permalink structure is set to Post name and I have clicked Save changes to make sure that any pending .htaccess
changes were saved. Category links work fine. Here's a list of PHP files in my theme root:
- 404.php
- front-page.php
- functions.php
- index.php
- pagebottom.php
- pagetop.php
- single.php
- taxonomy.php
Any idea why the archive link isn't working?
I'm writing my own WordPress theme and I'm having problems with the archive page. My archive link yields a 404 Not Found. I get this link from get_post_type_archive_link("post")
and it just adds /archives
to the base URL of my website.
My permalink structure is set to Post name and I have clicked Save changes to make sure that any pending .htaccess
changes were saved. Category links work fine. Here's a list of PHP files in my theme root:
- 404.php
- front-page.php
- functions.php
- index.php
- pagebottom.php
- pagetop.php
- single.php
- taxonomy.php
Any idea why the archive link isn't working?
Share Improve this question asked Apr 19, 2013 at 20:53 PieterPieter 1175 bronze badges 11 | Show 6 more comments2 Answers
Reset to default 1I had the same problem: the template hierarchy is not serving up the right file from the hierarchy (at least it should serve index.php if there is no archive.php), but instead it gives a 404.
My solution is to go to the wp-admin interface, select settings>permalinks and change the common settings to some other permalink setting (I changed it from "post name" to "day and name"). Now try again and it should work. Afterwards you can change the settings back to where they were (in my case: "post name") and it will still work, no 404.
Please have a look at WordPress Template Hierarchy here.. For your problem with Archive page you need to create Archive.php file in the theme root. If you want to create separate Archive page for different custom post type then just add post-type name prefix in archive.php file. Example product-archive.php Here is small example for archive page.
File name:- archive.php
<?php
/* Template Name: Archives */ get_header(); ?>
<?php the_post(); ?>
<h1 class="entry-title"><?php the_title(); ?></h1>
<?php get_search_form(); ?>
<h2>Archives by Month:</h2>
<ul>
<?php wp_get_archives('type=monthly'); ?>
</ul>
<h2>Archives by Subject:</h2>
<ul>
<?php wp_list_categories(); ?>
</ul>
</div><!-- #content -->
index.php
toarchive.php
, but it doesn't change anything. The template hierarchy sheet confirms that it shouldn't matter, since WordPress will useindex.php
as a fallback anyway. – Pieter Commented Apr 20, 2013 at 7:28