wordpress主題開發(fā):導(dǎo)航菜單函數(shù)wp_nav_menu()使用方
導(dǎo)讀:建站技術(shù)建站技術(shù)我們?cè)谧鰓ordpress主題開發(fā)的時(shí)候,必不可少的是要讀取后臺(tái)外觀-菜單中的導(dǎo)航結(jié)構(gòu),那么就需要用到wp_nav_menu()函數(shù),本篇文章小編問大家介紹wp搭建網(wǎng)站信息技術(shù)網(wǎng)站。
我們?cè)谧鰓ordpress主題開發(fā)的時(shí)候,必不可少的是要讀取后臺(tái)外觀-菜單中的導(dǎo)航結(jié)構(gòu),那么就需要用到wp_nav_menu()函數(shù),本篇文章小編問大家介紹wp_nav_menu()函數(shù)的使用方法。
wp_nav_menu()函數(shù)使用非常的簡單,只需要在你需要的地方放入以下代碼即可:
其中$args是函數(shù)的參數(shù),下面會(huì)詳細(xì)說明:
<?php $defaults = array( 'theme_location' => '',//用于在調(diào)用導(dǎo)航菜單時(shí)指定注冊(cè)過的某一個(gè)導(dǎo)航菜單名,如果沒有指定,則顯示第一個(gè) 'menu' => '',//使用導(dǎo)航菜單的名稱調(diào)用菜單,可以是 id, slug, name (按順序匹配的) 。 'container' => 'div',//最外層容器標(biāo)簽名 'container_class' => '',//最外層容器class名 'container_id' => '',//最外層容器id值 'menu_class' => 'menu',//ul 節(jié)點(diǎn)的 class 屬性值。 'menu_id' => '',//ul 節(jié)點(diǎn)的 id 屬性值。 'echo' => true,//確定直接顯示導(dǎo)航菜單還是返回 HTML 片段,如果想將導(dǎo)航的代碼作為賦值使用,可設(shè)置為false。 'fallback_cb' => 'wp_page_menu',//備用的導(dǎo)航菜單函數(shù),用于沒有在后臺(tái)設(shè)置導(dǎo)航時(shí)調(diào)用 'before' => '',//顯示在導(dǎo)航a標(biāo)簽之前 'after' => '',//顯示在導(dǎo)航a標(biāo)簽之后 'link_before' => '',//顯示在導(dǎo)航鏈接名之前 'link_after' => '',//顯示在導(dǎo)航鏈接名之后 'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>',//使用字符串替換修改ul的class。 'depth' => 0,//顯示菜單的深度, 當(dāng)數(shù)值為 0 時(shí)顯示所有深度的菜單。 'walker' => ''//自定義的遍歷對(duì)象,調(diào)用一個(gè)對(duì)象定義顯示導(dǎo)航菜單。 ); wp_nav_menu( $defaults ); ?>使用
<?php wp_nav_menu($args) ;?>讀取出來的導(dǎo)航菜單HTML結(jié)構(gòu)如下
<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技術(shù)文章主頁發(fā)布于:2023-07-23 ,文章wordpress主題開發(fā):導(dǎo)航菜單函數(shù)wp_nav_menu()使用方主要講述使用方法,函數(shù),建站網(wǎng)站建設(shè)源碼以及服務(wù)器配置搭建相關(guān)技術(shù)文章。轉(zhuǎn)載請(qǐng)保留鏈接: http://www.bifwcx.com/article/web_35326.html
為你推薦與wordpress主題開發(fā):導(dǎo)航菜單函數(shù)wp_nav_menu()使用方相關(guān)的文章
-
通王TWCMS 2.0.3網(wǎng)站模板程序下載
(126)人喜歡 2024-01-15 -
Windows官方原版在哪里下載
(175)人喜歡 2024-01-15 -
WordPress網(wǎng)站模板發(fā)帖標(biāo)題顏色設(shè)置
(131)人喜歡 2024-01-07 -
修改discuz論壇帖子標(biāo)題80字符的長度限制
(249)人喜歡 2024-01-07 -
wordpress程序調(diào)用不帶超鏈接的Tag標(biāo)簽
(234)人喜歡 2024-01-05 -
網(wǎng)站在不同時(shí)期需調(diào)整內(nèi)容更新的方向
(112)人喜歡 2023-08-12