首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >编辑Wordpress Nav菜单Walker

编辑Wordpress Nav菜单Walker
EN

WordPress Development用户
提问于 2018-02-07 06:52:47
回答 2查看 340关注 0票数 1

我已经连接T5_Nav_Menu_Walker到我的WP网站。https://gist.github.com/thefuxia/1053467

我希望定制我的WP菜单,使其能够通过FontAwesome类从want添加图标。截图:显示

但是当我在菜单中添加CSS类时,在HTML代码中没有输出,因为我使用t5_nav_walker。我怎样才能在这个wordpress中添加图标?此游行者的Php代码:

代码语言:javascript
复制
';
        // $output .= 'current ? ' class="current"':'').'>';
        $attributes  = 'class="app-menu__item"';

        ! empty ( $item->attr_title )
            // Avoid redundant titles
            and $item->attr_title !== $item->title
            and $attributes .= ' title="' . esc_attr( $item->attr_title ) .'"';

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



        $attributes  = trim( $attributes );
        $title       = apply_filters( 'the_title', $item->title, $item->ID );
        $item_output = "$args->before$args->link_before$title"
                        . "$args->link_after$args->after";

        // Since $output is called by reference we don't need to return anything.
        $output .= apply_filters(
            'walker_nav_menu_start_el'
            ,   $item_output
            ,   $item
            ,   $depth
            ,   $args
        );
    }

    /**
     * @see Walker::start_lvl()
     *
     * @param string $output Passed by reference. Used to append additional content.
     * @return void
     */
    public function start_lvl( &$output )
    {
        $output .= '';
    }

    /**
     * @see Walker::end_lvl()
     *
     * @param string $output Passed by reference. Used to append additional content.
     * @return void
     */
    public function end_lvl( &$output )
    {
        $output .= '';
    }

    /**
     * @see Walker::end_el()
     *
     * @param string $output Passed by reference. Used to append additional content.
     * @return void
     */
    function end_el( &$output )
    {
        $output .= '';
    }
}
EN

回答 2

WordPress Development用户

回答已采纳

发布于 2018-02-07 09:08:00

您需要为菜单项创建其他字段。因为如果要使用类字段,则会阻止向链接中添加其他类。但是如果可以的话-在链接标题之前创建。@Dilip Gupta给了你解决方案。

票数 1
EN

WordPress Development用户

发布于 2018-02-07 08:26:33

看,您需要更新您的$item_output变量。方阵输出此格式的图标。

您需要像这样在您的中添加这个

代码语言:javascript
复制
$item_output = "$args->before"
    . ""
        . "$args->link_before"
        . ""
        . "$title"
    . ""
    . "$args->link_after"
    . "$args->after";

$variable_which_stores_fontawesomme_value应该等于fa fa-angle-right

票数 1
EN
页面原文内容由WordPress Development提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://wordpress.stackexchange.com/questions/293365

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档