[英]Why do i have 2 times the same navbar instead of 2 different navbars in wordpress?
今天我提出另一個問題。 在我自己的 wordpress 主題中,我創建了 2 個導航菜單:navbar_pc 和 navbar_mobile。 當我嘗試實現這兩個導航欄時,只有移動導航欄出現在源代碼中。 這是這些文件的內容:navbar_pc:
<nav>
<?php
$argsforpcnavbar=array (
"theme-location" => "nav_pc"
);
wp_nav_menu($argsforpcnavbar);
?>
</nav>
和 navbar_mobile:
<div class="allnavbars-wrapper">
<?php get_template_part("template_parts/navbar_pc"); ?>
<?php get_template_part("template_parts/navbar_mobile"); ?>
</div>
這些在 header.php 中被調用並注冊為菜單和 header.php
function register_my_menus() {
register_nav_menus(
array(
'nav_pc' => __( 'Navigationsmenü für PCs' ),
'nav_mobile' => __( 'Navigationsmenü für mobile Endgeräte' )
)
);
}
add_action( 'init', 'register_my_menus' );
在 functions.php 中,它們注冊如下:
function register_my_menus() { register_nav_menus( array( 'nav_pc' => __( 'Navigationsmenü für PCs' ), 'nav_mobile' => __( 'Navigationsmenü für mobile Endgeräte' ) ) ); } add_action( 'init', 'register_my_menus' );
我該如何解決這個問題? 我將它們都分配給了它們的位置,但是 navbar_mobile 出現了 2 次,或者只有 navbar_mobile 出現了。 當然,導航標簽在下面關閉。 別擔心。 navbar_pc 僅在我刪除 navbar_mobile 時出現。
提前致謝,
你的阿爾文:)
您可以為兩者添加此條件
if(wp_is_mobile()){
//put the mobile menu code
}else{
// put the desktop menu code
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.