我要給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 '
", "", preg_replace("/]*>]*>/", "", wp_nav_menu(array('theme_location' => $location, 'echo' => false)) )).'';}function wp_nav2_menu($class='nav2', $location='nav2'){ echo '
", "", preg_replace("/]*>]*>/", "", wp_nav_menu(array('theme_location' => $location, 'echo' => false)) )).'';}function wp_nav3_menu($class='nav3', $location='nav3'){ echo '
", "", 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 '
", "", preg_replace("/]*>]*>/", "", wp_nav_menu(array('theme_location' => $location, 'echo' => false)) )).'';}function wp_nav2_menu($class='nav2', $location='nav2'){ echo '
", "", preg_replace("/]*>]*>/", "", wp_nav_menu(array('theme_location' => $location, 'echo' => false)) )).'';}function wp_nav3_menu($class='nav3', $location='nav3'){ echo '
", "", 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