2 回答

TA貢獻(xiàn)2041條經(jīng)驗(yàn) 獲得超4個(gè)贊
我不確定為什么 WP 核心has_term()功能在這種情況下不起作用,但您可以執(zhí)行以下操作,使用get_the_terms()并執(zhí)行array_search()結(jié)果。
function has_custom_taxonomy_term($termSlug, $taxonomy, $postId = null) {
$terms = get_the_terms($postId, $taxonomy);
if (isset($terms->errors)) {
// taxonomy doesn't exist
return false;
}
return array_search($termSlug, array_column($terms, 'slug')) !== false;
}
if (has_custom_taxonomy_term('skaga', 'hoteller')) {
get_template_part( 'includes/partials/header/header-menu-skaga' );
}

TA貢獻(xiàn)1811條經(jīng)驗(yàn) 獲得超5個(gè)贊
嗨,本,
謝謝您的回復(fù)。
我已經(jīng)嘗試過(guò)了,并嘗試了其他分類(lèi)法的 and and elseif,所以他們得到了 get_ 另一個(gè)模板部分,但沒(méi)有運(yùn)氣。
這就是我嘗試使用它的方式,你能發(fā)現(xiàn)錯(cuò)誤的部分嗎?
function has_custom_taxonomy_term($termSlug, $taxonomy, $postId = null) {
$terms = get_the_terms($postId, $taxonomy);
if (isset($terms->errors)) {
// taxonomy doesn't exist
return false;
}
return array_search($termSlug, array_column($terms, 'slug')) !== false;
}
if (has_custom_taxonomy_term('sabrokro', 'hoteller')) {
get_template_part( 'includes/partials/header/header-menu-sabrokro' );
}
elseif (has_custom_taxonomy_term('odder-parkhotel', 'hoteller')) {
get_template_part( 'includes/partials/header/header-menu-odder' );
}
elseif (has_custom_taxonomy_term('skaga', 'hoteller')) {
get_template_part( 'includes/partials/header/header-menu-skaga' );
}
elseif (has_custom_taxonomy_term('hotel-hanstholm', 'hoteller')) {
get_template_part( 'includes/partials/header/header-menu-hanstholm' );
}
再次感謝!
- 2 回答
- 0 關(guān)注
- 113 瀏覽
添加回答
舉報(bào)