admin管理员组文章数量:1022488
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 -->
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- 1 Because you have no archive.php. – vancoder Commented Apr 19, 2013 at 20:57
- Beat me to it @vancoder :) – Andrew Bartel Commented Apr 19, 2013 at 21:00
- 1 Checkout the template heirarchy @Pieter codex.wordpress/Template_Hierarchy – Andrew Bartel Commented Apr 19, 2013 at 21:01
- Also check out this handy checklist. – vancoder Commented Apr 20, 2013 at 4:00
-
@vancoder I have tried copying
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
2 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 -->
本文标签: theme developmentPost archives link yields a 404 Not Found
版权声明:本文标题:theme development - Post archives link yields a 404 Not Found 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745511042a2153827.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
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