Archive template not working | WordPress.org

Hi,

Custom Post Types and their associated archive pages should work fine in Quark. Quark doesn’t override any templates. A couple of things to be aware of when creating CPTs:

  • Make sure to go to the Permalinks page and just re-save the page to flush the Permalinks

When registering your CPT, make sure:

  • ‘has_archive’ => true
  • ‘public’ => true
  • ‘rewrite’ => ‘comics’ // This is the slug name to use for the CPT

As an example, if I create a CPT with 'the_type' => 'comic' and then I also use 'rewrite' => 'comics' the CPT archive page would be at yoursitename.com/comics.

To create a custom template, follow the rules outlined here in the Template Hierarchy. For my example above, the archive template would be called archive-comic.php (i.e. archive-$posttype.php). And again, flushing the permalinks is really important.

You can learn more about CPTs on the following links within the wordpress[dot]org developer reference:
Custom Post Types
Registering Custom Post Types

Lastly, try adding the following code to your functions.php for debugging. This code will show the name of the current template being used, at the top of the page (when logged in).

/**
* Debug function to show the name of the current template being used
*/
function mytheme_show_template() {
	global $template;
	if ( is_user_logged_in() ) {
		echo '<div style="background-color:#000;color:#fff;z-index:9999;position:absolute;top:0;">';
		print_r( $template );
		if ( is_single() ) {
			echo ' (and using Post Format: ' . ucfirst( get_post_format() ? get_post_format() : 'standard' ) . ')';
		}
		echo '</div>';
	}
}
add_action( 'wp_head', 'mytheme_show_template' );

Thread Starter
SJW

(@whitsey)

I can access /providers/ which shows all my posts within the CPT service-providers.

This would indicate to me that:

  1. CPT permalink is working (I can see all posts via the /providers/ permalink)
  2. has_archive is true (posts are being displayed on /providers/ )
  3. public is true (it is showing publicly on /providers/)
  4. rewrite is providers (CPT is service-providers but permalink is providers)

When I add the code to functions, it says the template is using quark/index.php

even though I have the following files in the child theme directory (all the same file just copied):

  1. archive-provider.php
  2. archive-providers.php
  3. archive-service-provider.php
  4. archive-service-providers.php

I have saved permalinks at least 5-10 times now.

Thread Starter
SJW

(@whitsey)

Scratch that – looks like the template file is now showing. After adding the code to functions.php the layout changed. This has baffled me but I guess I just accept it works now…

archive-service-provider.php appears to be the working file…

  • This reply was modified 12 minutes ago by SJW.

Glad to hear its all working for you now 🙂

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer