Technology

How to create an Archive page for Custom Post Type in WordPress

2025-03-26 02:54:59


Custom Post Type is a feature that helps you manage and display different types of content separately, such as portfolios, reviews, or products, making your website more organized and allowing visitors to find information more easily.


However, creating an Archive page for a Custom Post Type can be complex for beginners. In this article, we will teach you how to create an Archive page for a Custom Post Type in WordPress in a detailed and easy-to-understand manner.




What is the Archive page for a Custom Post Type?

Normally, WordPress already has two standard post types: "Posts" and "Pages." Some plugins, such as WooCommerce, add their own Custom Post Types, like "Products."


When you create a Custom Post Type, WordPress will automatically generate an Archive page for it, which is a page that collects all posts of that Custom Post Type. However, the theme you are using may not have a template for the Custom Post Type and might use the default template instead.


If you want to customize the display of the Archive page, you can create your own template. We will guide you on how to do this in the following section.



Enable Archive for Custom Post Type

Before creating an Archive page, make sure that your Custom Post Type supports the Archive function. You can easily check this, for example, if you have a Custom Post Type named "movies" and have enabled SEO-friendly permalinks, the URL of the Archive page should be:

https://example.com/movies

If you encounter a 404 page, it means that the Archive function for your Custom Post Type is not enabled.



How to enable Archive

1. Use a plugin (such as CPT UI)

If you create a Custom Post Type using a plugin like "Custom Post Type UI (CPT UI)," go to the plugin settings and enable the "Has Archive" option.


2. Use the code

If you create a Custom Post Type with code, modify the register_post_type function by adding 'has_archive' => true:  จริง:


add_action( 'init', 'create_post_type' );

function create_post_type() {

    register_post_type( 'movies',

        array(

            'labels' => array(

                'name' => __( 'Movies' ),

                'singular_name' => __( 'Movie' )

            ),

            'public' => true,

            'has_archive' => true,

        )

    );

}


Save the changes and try loading the Archive page again.



Customizing the Archive page for Custom Post Type

1. Create a specific template

If you want the Archive page of a Custom Post Type to look different from the general Archive page of the website, you can create your own template file.

How to create a template

  • Access your theme folder via FTP or File Manager in the hosting.
  • Copy the archive.php file and rename it to archive-{posttype}.php (for example, archive-movies.php if your Custom Post Type is "movies").
  • Open this file with a Text Editor and edit the code as needed.
  • Upload the file back to your theme.


2. Use a Page Builder like SeedProd

Another easier method is to use the SeedProd plugin, which is a drag-and-drop page builder that doesn't require coding.

How to use SeedProd

  • Install and activate the SeedProd plugin.
  • Go to SeedProd » Landing Pages and click "Add New Landing Page"
  • Choose the desired template or start from a blank page.
  • Use the Drag & Drop tool to add a "Posts Block" and configure it to display only the desired Custom Post Type.
  • Adjust the design appropriately and click "Publish."




Creating and customizing Archive pages for Custom Post Types in WordPress helps keep your website organized and makes it easier for users to find information. You can either edit the code directly or use plugins like SeedProd to conveniently design Archive pages.

Leave a comment :