我要為WordPress增加自訂選單
方法:
第一步:functions.php
<code>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 '<ul class="'.$class.'">'.str_replace("</ul></div>", "", preg_replace("/<div[^>]*><ul[^>]*>/", "", wp_nav_menu(array('theme_location' => $location, 'echo' => false)) )).'</ul>'; } function wp_nav2_menu($class='nav2', $location='nav2'){ echo '<ul class="'.$class.'">'.str_replace("</ul></div>", "", preg_replace("/<div[^>]*><ul[^>]*>/", "", wp_nav_menu(array('theme_location' => $location, 'echo' => false)) )).'</ul>'; } function wp_nav3_menu($class='nav3', $location='nav3'){ echo '<ul class="'.$class.'">'.str_replace("</ul></div>", "", preg_replace("/<div[^>]*><ul[^>]*>/", "", wp_nav_menu(array('theme_location' => $location, 'echo' => false)) )).'</ul>'; }</code>
第二步:page1.php
<code><?php wp_nav1_menu(); ?></code>
page2.php
<code><?php wp_nav2_menu(); ?></code>
page3.php
<code><?php wp_nav3_menu(); ?></code>
第三步:進入管理後台設定對應選單,前台即可正常顯示(選單建立完畢)
問題:
我按照上述步驟在page4.php頁面建立nav4的時候頁面出錯:
Fatal error: Call to undefined function wp_nav4_menu() in /…/page4.php on line x
我要為WordPress增加自訂選單
方法:
第一步:functions.php
<code>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 '<ul class="'.$class.'">'.str_replace("</ul></div>", "", preg_replace("/<div[^>]*><ul[^>]*>/", "", wp_nav_menu(array('theme_location' => $location, 'echo' => false)) )).'</ul>'; } function wp_nav2_menu($class='nav2', $location='nav2'){ echo '<ul class="'.$class.'">'.str_replace("</ul></div>", "", preg_replace("/<div[^>]*><ul[^>]*>/", "", wp_nav_menu(array('theme_location' => $location, 'echo' => false)) )).'</ul>'; } function wp_nav3_menu($class='nav3', $location='nav3'){ echo '<ul class="'.$class.'">'.str_replace("</ul></div>", "", preg_replace("/<div[^>]*><ul[^>]*>/", "", wp_nav_menu(array('theme_location' => $location, 'echo' => false)) )).'</ul>'; }</code>
第二步:page1.php
<code><?php wp_nav1_menu(); ?></code>
page2.php
<code><?php wp_nav2_menu(); ?></code>
page3.php
<code><?php wp_nav3_menu(); ?></code>
第三步:進入管理後台設定對應選單,前台即可正常顯示(選單建立完畢)
問題:
我按照上述步驟在page4.php頁面建立nav4的時候頁面出錯:
Fatal error: Call to undefined function wp_nav4_menu() in /…/page4.php on line x