第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

get_template_part 如果頁(yè)面有自定義分類(lèi)

get_template_part 如果頁(yè)面有自定義分類(lèi)

PHP
蕪湖不蕪 2022-07-16 18:41:22
我試圖根據(jù)頁(yè)面或帖子被標(biāo)記的類(lèi)別顯示不同的標(biāo)題菜單。我創(chuàng)建了兩個(gè)工具集分類(lèi)法,類(lèi)別和酒店。我希望所有酒店都有自己的菜單、徽標(biāo)和預(yù)訂菜單,但我無(wú)法讓 php 工作并定位類(lèi)別。我已經(jīng)嘗試了幾個(gè)片段,例如這個(gè):*< ?php if( has_term('skaga', 'hoteller') {get_template_part('includes/partials/header/header-menu-skaga'); }?>*我還嘗試了另一種在不同站點(diǎn)上工作的方法,但它針對(duì)兩種分類(lèi)法,我只需要它針對(duì)一種分類(lèi)法。*< ?php if( has_term('puder', 'produkttype') || has_term('senge', 'produkttype')) {get_template_part('partials/sections/section', 'trustpilot'); } ?>*我希望有人能闡明我做錯(cuò)了什么。非常感謝所有幫助!謝謝
查看完整描述

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' );

}


查看完整回答
反對(duì) 回復(fù) 2022-07-16
?
四季花海

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' );

}

再次感謝!


查看完整回答
反對(duì) 回復(fù) 2022-07-16
  • 2 回答
  • 0 關(guān)注
  • 113 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)