WordPress.org

Forums

[resolved] How to link in archive.php template file (3 posts)

  1. patv
    Member
    Posted 2 years ago #

    I have created custom post types in my WordPress installation, and I want to use archive-{custom post type}.php in order to list the respective custom post types.

    The websites I've visited seem to indicate that i <i>must</i> use this archive template file directly on a page create in my wordpress for the specific purpose of listing these post types...

    I find this abit conflicting since archive.php is a default template file used and recognized by WordPress so in my mind it should be useable without creating a WordPress page for this. Is this possible? If so, what's the URL I should expect to hit to get to this listing? is there a WordPress function that will generate me the permalink/url for this template file without having to create a new page?

    Thanks.

  2. patv
    Member
    Posted 2 years ago #

    I've been able to figure out the url for WordPress to point directory to my archives. Unfortunately, it's calling my index.php template file instead of using my archive.php or variant of this template file.

    I've specified has_archives in the initialiation of my custom post types, though it doesn't fix this problem.

  3. patv
    Member
    Posted 2 years ago #

    Resolved. File misnamed. For any other readers, these are the steps required in order to create a listing of your custom posts:

    1- Register your custom post type reference. Be sure to specify has_archive.
    2-Create a template file called archive.php (NOT archives.php).
    3-Create sub template files such as archive-{custom post type}.php to retrieve specific listings.

    If, for example, your custom post is found at http://www.example.com/news/news-instance-1, then /news will be the level at which you will need to hit to get its archives page (so http://www.example.com/news/).

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags