Consider I've 3 template files
archive.php
archive-books.php
common.php <-- required_once by both archive.php & archive-books.php
So whether archive-books.php
or archive.php
is being loaded depends on the current post type.
Since they both include common.php
, in the common.php
, how to I know which current WordPress template is picked? i.e. archive.php
or archive-books.php
?
Consider I've 3 template files
archive.php
archive-books.php
common.php <-- required_once by both archive.php & archive-books.php
So whether archive-books.php
or archive.php
is being loaded depends on the current post type.
Since they both include common.php
, in the common.php
, how to I know which current WordPress template is picked? i.e. archive.php
or archive-books.php
?
- 2 And when/where do you want to obtain that information, because this is important...? – Krzysiek Dróżdż Commented Apr 2, 2019 at 9:40
2 Answers
Reset to default 0In this specific case you could simply follow the logic: determine if you're on an archive page and what the current post type is. Like this:
if (is_archive() && 'books' == get_post_type) { do your thing }
Or you could use the function specific for checking this:
if (is_post_type_archive('books')) { do your thing }
try this to check if your specific post type archive file is present
$postType = get_query_var( 'post_type' );
if(file_exists('archive-'.$postType.'.php')){
// You have the specific archive file for the post type
}else{
// You don't have the specific archive file for the post type
}