Site logo

Archived topic

How do I create a CPT archive page that lists all my CPTS?

3 replies · Started by Pete on September 14, 2015

Viewing posts 1–4 of 4

How do I create a CPT archive page that lists all my CPTS like archive.php does for my categories?
My CPT is called "profile" and so I copied the archive.php file into my child theme and renamed it archive-profile.php but it ain't doin' nutin'.

WP says this...

archive-{post_type}.php
If your custom post type were 'product', and/or query_var = "product", WordPress would look for archive-product.php to display the archive of posts.

But when I go to mydomain.com/profile it doesn't list them like mydomain.com/category lists my normal posts. Instead I get a 404.

I'm guessing I'm missing something important!

I think I have to add this piece of code... but i'm not sure where or how?

$args = array( 'post_type' => 'profile', 'posts_per_page' => 10 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
  the_title();
  echo '<div class="entry-content">';
  the_content();
  echo '</div>';
endwhile;

All I want to do is have a separate archive.php and single.php for my custom post type so I can customise different from the normal posts.

Naming it like that should work (archive-{post_type}.php).

If going to the page is giving you a 404, rebuild your permalinks by going to "Settings > Permalinks" and clicking the save button.

This archived topic is closed to new replies.