• Resolved SJW

    (@whitsey)


    I have created a Custom Post Type called service-providers

    I have an archive URL working which shows all providers under /providers/ and shows individual providers as /provider/abc-company

    I am now trying to build a specific archive page so have copied the category.php file and named it archive-providers.php

    I have made modifications to archive-providers.php and yet none of the changes are visible. I’ve also tried renaming the file to

    • archive-service-providers.php
    • archive-service-provider.php
    • archive-provider.php

    None of these change the appearance of my archive results page on the frontend. Does quark ignore the archive.php file? Or do I need to use a different naming convention?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Theme Author Anthony Hortin

    (@ahortin)

    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 8 months, 1 week ago by SJW.
    Theme Author Anthony Hortin

    (@ahortin)

    Glad to hear its all working for you now ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Archive template not working’ is closed to new replies.