How Can You Create a Custom Archive Page for a Custom Post Type?

Are you looking to create a custom archive page for your post types in WordPress? Maybe you’ve tried using plugins before and found them too complex or limiting. Whatever the reason, don’t worry! You can create a WordPress archive page for custom post type with or without the need for plugins.

With a few simple steps, you can enable and customize your custom post type’s archive page directly within your theme. It’s easier than you might think, and the best part?

Let’s show you exactly how to create a WordPress archive page for custom post type and explore some helpful tips.

What Is a WordPress Archive Page for Custom Post Type?

Simply WordPress archive page for custom post type to organize your WordPress site. These pages group and display content from custom post types in a neat and user-friendly way.

Whether you’re working with portfolio items, testimonials, or products, a Custom Post Type Archive Page showcases these posts separately from your regular blog posts. Isn’t it great that you are getting personalized archive pages?

So, if you’ve ever felt overwhelmed by your WordPress site’s growing content, now you can keep everything organized and easy to navigate with no hassle.

Why Archive Pages Matter?

Why should you care about a WordPress archive page for a custom post type?

Well, if you’ve created a custom post type for your site, this archive page automatically gathers and displays all posts related to it. There will be no more endless scrolling through categories or tags. Your audience will find exactly what they’re looking for quickly.

Plus, this archive page is customizable. So you can match it with your site’s design and structure. 

Undoubtedly, to create a well-organized, smooth user experience without any complicated plugins or code archive pages are a great solution. You can make your content shine and your visitors happy with Custom Post Type Archives!

Step on Create a Custom Post-Type Archive Page in WordPress Without Using Plugins

Here are only three easy steps you can take to create a WordPress archive page for custom post type in WordPress.

Step 1: Enable Archive for Your Custom Post Type

Before you can create a custom archive page, you need to ensure that the archive feature is enabled for your custom post type. Do this in the register_post_type() function in your theme’s functions.php file or a site-specific plugin. Do this When registering a custom post type in WordPress.

Example:

<?php
// Function to create a custom post type
function create_custom_post_type() {
    // Arguments for registering the custom post type
    $args = array(
        'label'              => 'Example Post Type', // Label for the custom post type
        'public'             => true,               // Make it publicly accessible
        'has_archive'        => true,               // Enable archive pages for this post type
        'rewrite'            => array(
            'slug' => 'examples'                   // Customize the permalink structure
        ),
        'supports'           => array(
            'title', 'editor', 'thumbnail', 'excerpt', 'comments' // Features supported by the post type
        ),
        'menu_icon'          => 'dashicons-admin-post', // Icon in the admin menu
        'show_in_rest'       => true,               // Enable Gutenberg editor
    );

    // Register the custom post type
    register_post_type('example_post_type', $args);
}

// Hook the function to the 'init' action
add_action('init', 'create_custom_post_type');

Also, check 'has_archive' is set to true. So WordPress gets the signal your custom post type should have an archive page.

Step 2: Customizing Your Custom Post Type Archive Page

Here, we will see two methods of customizing your CPT archive page.

Method 1:

By default, WordPress uses a standard archive template to display all posts from your custom post type. If you want to make your archive page look different from your blog or other archive pages, you can customize it easily. Only create a custom template for your post type.

Start by connecting to your WordPress site using an FTP client. The File Manager in your hosting control panel also can work. Next, navigate to the /wp-content/themes/your-current-theme/ folder. Then, download the archive.php file to your computer.

Rename this file to archive-{posttype}.php, replacing {posttype} with your custom post type’s name (e.g., archive-cook.php for a custom post type called "Cook"). Open the renamed file in a text editor. Here, you can make any changes.

Once you're happy with the changes, save the file. Then upload it back to your theme's folder using FTP or File Manager.

Now, when you visit your custom post-type archive page, you’ll see your updated design.

Method 2:

The archive is enabled now. Next, WordPress will use the default archive template from your theme to display this custom post type’s archive. However, if you want a custom design or layout, you can create a new template file specifically for this post type.

Create a New Template File:

Navigate to your theme directory and create a new file named archive-your_post_type.php (replace your_post_type with the actual name of your custom post type).

For instance, if your post type is example_post_type, the file should be named archive-example_post_type.php.

Edit the Template File:

Open the new file and add the standard WordPress loop to display the posts. Here’s a simple example of what the file might look like:

<?php get_header(); ?>

<section>

    <header>

        <h1><?php post_type_archive_title(); ?></h1>

    </header>

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>

        <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>

            <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>

            <div class="entry-content">

                <?php the_excerpt(); ?>

            </div>

        </article>

    <?php endwhile; endif; ?>

</section>

<?php get_footer(); ?>

This is a basic loop that outputs the title and excerpt for each post. Feel free to customize it further.

Step 3: Test the Custom Archive Page

Now that customized your archive page, it's important to test it to ensure everything displays correctly:

Visit the Archive Page:

Type the URL into your browser’s address bar. The format should be like this: 

http://yourwebsite.com/your_post_type_slug/,

Replacing

your_post_type_slug

With the slug you defined in the rewrite argument of your

register_post_type function.

Conclusion

Creating a WordPress archive page for custom post types is actually pretty simple. Also, it gives you full control over how everything looks. By tweaking your theme's files, you can easily personalize the layout and display. And there is no need to worry about extra plugins or clutter.

Component 2
Tiny Solutions is dedicated to providing innovative and efficient WordPress plugins. Our team focuses on creating tools that simplify and enhance the WordPress experience, ensuring our users have the best possible solutions at their fingertips.