wordpress 菜单描述设置步骤

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(),


            )                                                                                                                                                                                                                                                                                                                                              

        );


    ?>

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容