theme development - Post archives link yields a 404 Not Found

I'm writing my own WordPress theme and I'm having problems with the archive page. My archive link yields a 404

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 to archive.php, but it doesn't change anything. The template hierarchy sheet confirms that it shouldn't matter, since WordPress will use index.php as a fallback anyway. – Pieter Commented Apr 20, 2013 at 7:28
 |  Show 6 more comments

2 Answers 2

Reset to default 1

I 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 -->

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745511045a4630772.html

相关推荐

  • theme development - Post archives link yields a 404 Not Found

    I'm writing my own WordPress theme and I'm having problems with the archive page. My archive link yields a 404

    3小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信