wordpress主題支援自訂菜單及修改css樣式實現方法

來源:互聯網
上載者:User

自己在製作wordpress主題的時候遇到這個問題,並且遇到了css樣式錯誤,其實很簡單,操作如下:
在主題中functions.php中加入:
register_nav_menus( array( 'menu' => __( 'menu', '' ), ) );
在主題導覽列貼上導航代碼: <?php wp_nav_menu( 'id=navbar' ); ?>
但是出現了css樣式錯誤
原來這個函數輸出的是下面的格式: 複製代碼 代碼如下:<div id="menubar">
<ul class="menus">
<li class="..."><a href="http://.../">Home</a></li>
<li class="..."><a href="http://.../">功能表項目1</a></li>
<li class="..."><a href="http://.../">功能表項目2</a></li>
<li class="..."><a href="http://.../">功能表項目3</a></li>
...
</ul>
</div>

沒事,過濾下就ok啦:
將代碼改成: 複製代碼 代碼如下:<?php
echo str_replace("</ul></div>", "", ereg_replace("<div[^>]*><ul[^>]*>", "", wp_nav_menu(array('theme_location' => 'primary', 'echo' => false)) ));
?>

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.