[英]How can I use is_archive() in index.php to retrieve specific archive based template in WordPress?
I'm developing a WordPress blog site.我正在开发一个 WordPress 博客站点。
I'm trying to get a specific template according to WordPress conditional tags as written bellow:我正在尝试根据 WordPress 条件标签获取特定模板,如下所示:
switch(1):
case(!is_single() && get_post_type() == 'post'):
get_template_part('/frontend/template-parts/general');
break;
case(is_single() && get_post_type() == 'post'):
get_template_part('/frontend/template-parts/single/single', get_post_format());
break;
case(is_archive()):
get_template_part('/frontend/template-parts/archives/category');
break;
endswitch;
and, it works fine for first two conditons.并且,它适用于前两个条件。 But, It's not workig, when I'm trying to get the category.php template located in '/frontend/template-parts/archives/' directory based on is_archive() conditional tag.
但是,当我试图根据 is_archive() 条件标签获取位于“/frontend/template-parts/archives/”目录中的 category.php 模板时,这不是工作。
How can I set templates like category.php, tag.php, archive.php, author.php dynamically, located on '/frontend/template-parts/archives/' directory based on is_archive() conditional tag placed in index.php as mentioned above. How can I set templates like category.php, tag.php, archive.php, author.php dynamically, located on '/frontend/template-parts/archives/' directory based on is_archive() conditional tag placed in index.php as上文提到的。
Thank you.谢谢你。
Try Below code.试试下面的代码。
switch(1):
case(!is_single() && get_post_type() == 'post'):
get_template_part('/frontend/template-parts/general');
break;
case(is_single() && get_post_type() == 'post'):
get_template_part('/frontend/template-parts/single/single', get_post_format());
break;
case(is_archive()):
get_template_part('/frontend/template-parts/archives/archive');
break;
case(is_category()):
get_template_part('/frontend/template-parts/archives/category');
break;
case(is_tag()):
get_template_part('/frontend/template-parts/archives/tag');
break;
case(is_author()):
get_template_part('/frontend/template-parts/archives/author');
break;
endswitch;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.