wordpress 菜單描述設(shè)置步驟

1、

在functions.php 添加類


class description_walker extends Walker_Nav_Menu

{

? ? function start_el(&$output, $item, $depth = 0, $args = NULL, $id = 0)

? ? {

? ? ? ? global $wp_query;

? ? ? ? $indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';


? ? ? ? $class_names = $value = '';


? ? ? ? $classes = empty( $item->classes ) ? array() : (array) $item->classes;


? ? ? ? $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) );

? ? ? ? $class_names = ' class="'. esc_attr( $class_names ) . '"';


? ? ? ? $output .= $indent . '<li id="menu-item-'. $item->ID . '"' . $value . $class_names .'>';


? ? ? ? $attributes ?= ! empty( $item->attr_title ) ? ' title="' ?. esc_attr( $item->attr_title ) .'"' : '';

? ? ? ? $attributes .= ! empty( $item->target ) ? ? ? ' target="' . esc_attr( $item->target ? ? ) .'"' : '';

? ? ? ? $attributes .= ! empty( $item->xfn ) ? ? ? ?? ' rel="' ? ?. esc_attr( $item->xfn ? ? ? ?) .'"' : '';

? ? ? ? $attributes .= ! empty( $item->url ) ? ' href="' . esc_attr( $item->url ) .'"' : '';

? ? ? ? $description ?= ! empty( $item->description ) ? '</br><p>'.esc_attr( $item->description ).'</p>' : '';


? ? ? ? $item_output = $args->before;

? ? ? ? $item_output .= '<a class=custom_hover_color'. $attributes .'>';

? ? ? ? $item_output .= $args->link_before .$prepend.apply_filters( 'the_title', $item->title, $item->ID ).$append;

? ? ? ? $item_output .= $description.$args->link_after;

? ? ? ? $item_output .= '</a>';

? ? ? ? $item_output .= $args->after;


? ? ? ? $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );

? ? }

}


2、在需要的頁面使用


<?php ?

? ? ? ? echo wp_nav_menu(

? ? ? ? ? ? array(

? ? ? ? ? ? ? ? "theme_location" => "cus",

? ? ? ? ? ? ? ? 'walker' => new description_walker(),


? ? ? ? ? ? ) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?

? ? ? ? );


? ? ?>

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容