0

Suppose i have registered five custom post type like this

america
china
nepal
norway
chile

And to template the archive i should use like this inside theme folder isn't it?

archive-america.php
archive-china.php

and so on?

But the thing is all of them have same code? And i don't want to make five files with same coding ? And basically it violates DRY as welll

Is there any hooks etc. like template redirect etc so that i can use one php file for such selected custom post type like

archive-country.php

i know i can use archive.php but i want to show same teamplate for some selected custom post .

Is it possible?

thank you

1 Answer 1

1

There are template filters for all types of queries. You could use archive_template in this case.

function wpd210689_template_filter( $archive_template ) {
    $post_types = array( 'america', 'china', 'nepal', 'norway', 'chile' );
    if ( is_post_type_archive ( $post_types ) ) {
        $archive_template = locate_template( 'archive-country.php' );
    }
    return $archive_template;
}
add_filter( 'archive_template', 'wpd210689_template_filter' ) ;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.