WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Custom post type uses index.php instead of archive-[name].php (12 posts)

  1. Anders Norén
    Member
    Posted 2 years ago #

    I'm developing a site for a client who requires a custom post type called fanzines. I have gotten single-fanzine.php working as intended, but instead of using archive-fanzine.php the site is using index.php to display the archive pages for the post type.

    I'm assuming that the error is located in index.php, since the site is using neither archive.php nor archive-fanzine.php for displaying the post type archive, but I can't find it. I have uploaded a text file with the contents of index.php here.

    Oh, and I have specified 'has_archive' => true in functions.php.

  2. keesiemeijer
    moderator
    Posted 2 years ago #

    Try:
    - re-saving your current permalink structure at Settings > Permalinks in your admin panel.

    sometimes this helps.

  3. Anders Norén
    Member
    Posted 2 years ago #

    Didn't work, unfortunately.

  4. keesiemeijer
    moderator
    Posted 2 years ago #

    Are the correct fanzine posts shown by index.php? Do you have a Page with the same title as you registered your fanzine post type with?

    Can you paste and submit the full code of how you registered your custom post type into a pastebin.com and post the link to it here? see the Forum Rules for posting code and using the pastebin.

  5. Anders Norén
    Member
    Posted 2 years ago #

    Yes to the first question, no to the second. I've posted the code here: http://pastebin.com/6UZuMe9S

  6. Anders Norén
    Member
    Posted 2 years ago #

    When I use http://localhost/demosajt/?post_type=fanzine instead of http://localhost/demosajt/fanzine/, the posts are displayed properly.

  7. keesiemeijer
    moderator
    Posted 2 years ago #

    Try it with 'has_archive' => true in the $args array in stead of the $labels array.
    http://codex.wordpress.org/Function_Reference/register_post_type
    And re-save your permalink structure after.

  8. Anders Norén
    Member
    Posted 2 years ago #

    Didn't work either. I have looked all over but can't figure it out.

  9. keesiemeijer
    moderator
    Posted 2 years ago #

    Did you re-save your permalink structure?

  10. Anders Norén
    Member
    Posted 2 years ago #

    That did the trick! I tried to re-save it earlier, but the misplaced has_archive must have gotten in the way or something. Works like a charm now though. Thanks!

  11. keesiemeijer
    moderator
    Posted 2 years ago #

    I'm glad you got it resolved.

  12. lord_dev
    Member
    Posted 1 year ago #

    This problem seems to be happening but with Pages instead of a CPT.

    I am using the Custom Post Type UI plugin. Has Archive is set to 'True' and I keep refreshing the permalinks. Instead of displaying the page, it displays index.php instead.

    Any ideas?

    Thanks

Topic Closed

This topic has been closed to new replies.

About this Topic