admin管理员组文章数量:1025481
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
}
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
}
本文标签: pluginsHow to get current template file used by WordPress
版权声明:本文标题:plugins - How to get current template file used by WordPress? 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745636183a2160461.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论