wordpress主題開發:導航菜單函數wp_nav_menu()使用方
導讀:建站技術建站技術我們在做wordpress主題開發的時候,必不可少的是要讀取后臺外觀-菜單中的導航結構,那么就需要用到wp_nav_menu()函數,本篇文章小編問大家介紹wp搭建網站信息技術網站。
我們在做wordpress主題開發的時候,必不可少的是要讀取后臺外觀-菜單中的導航結構,那么就需要用到wp_nav_menu()函數,本篇文章小編問大家介紹wp_nav_menu()函數的使用方法。
wp_nav_menu()函數使用非常的簡單,只需要在你需要的地方放入以下代碼即可:
其中$args是函數的參數,下面會詳細說明:
<?php $defaults = array( 'theme_location' => '',//用于在調用導航菜單時指定注冊過的某一個導航菜單名,如果沒有指定,則顯示第一個 'menu' => '',//使用導航菜單的名稱調用菜單,可以是 id, slug, name (按順序匹配的) 。 'container' => 'div',//最外層容器標簽名 'container_class' => '',//最外層容器class名 'container_id' => '',//最外層容器id值 'menu_class' => 'menu',//ul 節點的 class 屬性值。 'menu_id' => '',//ul 節點的 id 屬性值。 'echo' => true,//確定直接顯示導航菜單還是返回 HTML 片段,如果想將導航的代碼作為賦值使用,可設置為false。 'fallback_cb' => 'wp_page_menu',//備用的導航菜單函數,用于沒有在后臺設置導航時調用 'before' => '',//顯示在導航a標簽之前 'after' => '',//顯示在導航a標簽之后 'link_before' => '',//顯示在導航鏈接名之前 'link_after' => '',//顯示在導航鏈接名之后 'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>',//使用字符串替換修改ul的class。 'depth' => 0,//顯示菜單的深度, 當數值為 0 時顯示所有深度的菜單。 'walker' => ''//自定義的遍歷對象,調用一個對象定義顯示導航菜單。 ); wp_nav_menu( $defaults ); ?>使用
<?php wp_nav_menu($args) ;?>讀取出來的導航菜單HTML結構如下
<div class="menu-%e5%af%bc%e8%88%aa-container"><ul id="menu-%e5%af%bc%e8%88%aa" class="menu"><li id="menu-item-62" class="menu-item menu-item-type-custom menu-item-object-custom current-menu-item current_page_item menu-item-home menu-item-62"><a href="http://localhost/wordpress/" rel="external nofollow" rel="external nofollow" >首頁</a></li> <li id="menu-item-32" class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-32"><a href="http://localhost/wordpress/category/html" rel="external nofollow" rel="external nofollow" >HTML</a></li> <li id="menu-item-33" class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-33"><a href="http://localhost/wordpress/category/css" rel="external nofollow" rel="external nofollow" >CSS</a></li> <li id="menu-item-34" class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-34"><a href="http://localhost/wordpress/category/javascript" rel="external nofollow" rel="external nofollow" >JavaScript</a></li> <li id="menu-item-35" class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-35"><a href="http://localhost/wordpress/category/jquery" rel="external nofollow" rel="external nofollow" >jquery</a></li> <li id="menu-item-36" class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-36"><a href="http://localhost/wordpress/category/php" rel="external nofollow" rel="external nofollow" >PHP</a></li> <li id="menu-item-37" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-37"><a href="http://localhost/wordpress/sample-page" rel="external nofollow" rel="external nofollow" >示例頁面</a></li> </ul></div>聲明: 本文由我的SEOUC技術文章主頁發布于:2023-07-23 ,文章wordpress主題開發:導航菜單函數wp_nav_menu()使用方主要講述使用方法,函數,建站網站建設源碼以及服務器配置搭建相關技術文章。轉載請保留鏈接: http://www.bifwcx.com/article/web_35326.html