时间:2021-07-01 10:21:17 帮助过:6人阅读
if (function_exists('register_nav_menus')){
register_nav_menus( array(
'nav1' => __('网站导航1'),
'nav2' => __('网站导航2'),
'nav3' => __('网站导航3'),
));
}
function wp_nav1_menu($class='nav1', $location='nav1'){
echo ''.str_replace("
", "", preg_replace("/]*>]*>/", "", wp_nav_menu(array('theme_location' => $location, 'echo' => false)) )).'
';
}
function wp_nav2_menu($class='nav2', $location='nav2'){
echo ''.str_replace("
", "", preg_replace("/]*>]*>/", "", wp_nav_menu(array('theme_location' => $location, 'echo' => false)) )).'
';
}
function wp_nav3_menu($class='nav3', $location='nav3'){
echo ''.str_replace("
", "", preg_replace("/]*>]*>/", "", wp_nav_menu(array('theme_location' => $location, 'echo' => false)) )).'
';
}
第二步:page1.php
page2.php
page3.php
第三步:进入管理后台设置对应菜单,前台即可正常显示(菜单创建完毕)
问题:
我按照以上步骤在page4.php页面创建nav4的时候页面出错:
Fatal error: Call to undefined function wp_nav4_menu() in /……/page4.php on line x
我要给WordPress增加自定义菜单
方法:
第一步:functions.php
if (function_exists('register_nav_menus')){
register_nav_menus( array(
'nav1' => __('网站导航1'),
'nav2' => __('网站导航2'),
'nav3' => __('网站导航3'),
));
}
function wp_nav1_menu($class='nav1', $location='nav1'){
echo ''.str_replace("
", "", preg_replace("/]*>]*>/", "", wp_nav_menu(array('theme_location' => $location, 'echo' => false)) )).'
';
}
function wp_nav2_menu($class='nav2', $location='nav2'){
echo ''.str_replace("
", "", preg_replace("/]*>]*>/", "", wp_nav_menu(array('theme_location' => $location, 'echo' => false)) )).'
';
}
function wp_nav3_menu($class='nav3', $location='nav3'){
echo ''.str_replace("
", "", preg_replace("/]*>]*>/", "", wp_nav_menu(array('theme_location' => $location, 'echo' => false)) )).'
';
}
第二步:page1.php
page2.php
page3.php
第三步:进入管理后台设置对应菜单,前台即可正常显示(菜单创建完毕)
问题:
我按照以上步骤在page4.php页面创建nav4的时候页面出错:
Fatal error: Call to undefined function wp_nav4_menu() in /……/page4.php on line x