簡體   English   中英

如何使用 index.php 中的 is_archive() 來檢索 WordPress 中基於存檔的特定模板?

[英]How can I use is_archive() in index.php to retrieve specific archive based template in WordPress?

我正在開發一個 WordPress 博客站點。

我正在嘗試根據 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;

並且,它適用於前兩個條件。 但是,當我試圖根據 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上文提到的。

謝謝你。

試試下面的代碼。

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM