How can I exclude page(s) from nav menu? I found some examples where field called "exclude" was added to args and reportedly it worked. Maybe it's just deprecated. I have version 4.1.5.
My current code is:
$avia_theme_location = 'avia';
$avia_menu_class = $avia_theme_location . '-menu';
$args = array(
'theme_location' => $avia_theme_location,
'menu_id' => $avia_menu_class,
'exclude' => '29, 30, 31, 32',
'menu_class' => 'menu av-main-nav',
'container_class' => $avia_menu_class.' av-main-nav-wrap'.$icon_beside,
'fallback_cb' => 'avia_fallback_menu',
'walker' => new avia_responsive_mega_menu()
);
wp_nav_menu($args);
Where 29,30,31 and 32 are pages IDs what I want to exclude and they are correct.
答案 0 :(得分:0)
你可以用这个:
$args = array(
// Other values,
'exclude' => array(29,30,31,32) // <-- Addedd ids to exclude
);
wp_nav_menu($args);
答案 1 :(得分:0)
你可以试试这个。 而不是
'exclude' => '29, 30, 31, 32',
尝试,
'post__not_in' => array( 29, 30, 31, 32 ),
答案 2 :(得分:0)
其实我解决了自己。这很重要: 'fallback_cb'=&gt; 'avia_fallback_menu'
我想在Enfold主题中排除Woocommerce页面。所以我在文件class-megamenu.php中发现了回调函数,我现在看起来像这样:
function avia_fallback_menu()
{
$current = "";
$exclude= (avia_get_option('frontpage').",".get_option( 'woocommerce_shop_page_id' ).",".get_option( 'woocommerce_cart_page_id' ).",".get_option( 'woocommerce_checkout_page_id' ).",".get_option( 'woocommerce_myaccount_page_id' ));
if (is_front_page()){$current = "class='current-menu-item'";}
if ($exclude) $exclude ="&exclude=".$exclude;
echo "<div class='fallback_menu av-main-nav-wrap'>";
echo "<ul class='avia_mega menu av-main-nav'>";
echo "<li $current><a href='".get_bloginfo('url')."'>".__('Domov','avia_framework')."</a></li>";
wp_list_pages('title_li=&sort_column=menu_order'.$exclude);
echo apply_filters('avf_fallback_menu_items', "", 'fallback_menu');
echo "</ul></div>";
}