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:
- CPT permalink is working (I can see all posts via the
/providers/
permalink) - has_archive is true (posts are being displayed on
/providers/
) - public is true (it is showing publicly on
/providers/
) - rewrite is
providers
(CPT isservice-providers
but permalink isproviders
)
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):
archive-provider.php
archive-providers.php
archive-service-provider.php
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 🙂