要為指定ID的分類(lèi)使用不同的搜索模板,其實(shí)很簡(jiǎn)單,通過(guò)以下方法,就可以實(shí)現(xiàn)為wordpress指定ID的分類(lèi)添加不同的搜索結(jié)果頁(yè)模板,具體操作步驟如下:

1、在你的WordPress主題目錄下,找到search.php文件。如果沒(méi)有這個(gè)文件,你可以創(chuàng)建一個(gè)。

2、在search.php文件中添加以下代碼:

<?php
$current_category = get_queried_object();
$wodepress_category_id = 666; // Replace 666 with the category ID you want to specify

if ($current_category->term_id == $wodepress_category_id) {
    // wodepress.com If the current classification ID matches the specified ID, use a custom search template 
    get_template_part('template-parts/custom-search-template');
} else {
    // If the current classification ID does not match the specified ID, use the default search template
    get_template_part('template-parts/default-search-template');
}
?>

3、在你的WordPress主題目錄下的template-parts文件夾中,創(chuàng)建兩個(gè)新文件:custom-search-template.php和default-search-template.php。

4、在custom-search-template.php文件中,編寫(xiě)你想要為指定分類(lèi)ID使用的自定義搜索模板代碼。

5、在default-search-template.php文件中,編寫(xiě)你想要為其他分類(lèi)ID使用的默認(rèn)搜索模板代碼。

6、保存所有更改,然后在WordPress后臺(tái)查看搜索結(jié)果頁(yè)面,看看是否按照預(yù)期顯示了不同的搜索模板。

注意:請(qǐng)確保將666替換為你要指定的分類(lèi)ID。