text Wp walker菜单
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了text Wp walker菜单相关的知识,希望对你有一定的参考价值。
IN FUNCTIONS.PHP
================
/**
* Include walker-menu
*/
require get_template_directory() . '/include/walker-menu.php';
Change register menu
--------------------
// This theme uses wp_nav_menu() in one location.
register_nav_menus( array(
'menu-1' => esc_html__( 'Primary', 'theme' ),
'menu-2' => esc_html__( 'Footer', 'theme' ),
) );
Walker-menu.php code
====================
<?php
/**
* Class Name: wp_materialize_navwalker
* GitHub URI: #
* Description: A custom WordPress nav walker class to "fully" implement the Materialize CSS nested navigation style in a custom theme using the WordPress manager
* Version: 1.0.0
* Author: Kailo - https://kailo.io
* Updated: Nov. 2, 2017 by Mackenzie Fritschle as a shoddy compatibility for multiple walkers
* License: MIT
* License URI: #
*/
class mainMenuWalker extends Walker_Nav_Menu
{
public function start_lvl(&$output, $depth = 0, $args = array())
{
if (isset($args->item_spacing) && 'discard' === $args->item_spacing) {
$t = '';
$n = '';
} else {
$t = "\t";
$n = "\n";
}
$indent = str_repeat($t, $depth);
$output .= "{$n}{$indent}<span class=\"dropper-nav\"><i class=\"fa fa-angle-down\" aria-hidden=\"true\"></i></span>
<ul class=\"dropdown-content\">{$n}";
}
}
In header.php (or any place on site where call menu)
====================================================
<nav class="main-nav" role="navigation">
<?php
wp_nav_menu(array('walker' => new mainMenuWalker(), 'container'=>false, 'echo' => true, 'menu_class' => 'main-nav__list', 'theme_location'=>'menu-1', 'fallback_cb'=>false, 'before' => '', 'after' => '', 'link_before' => '', 'link_after' => '', 'depth' => 2, ));
?>
</nav>
以上是关于text Wp walker菜单的主要内容,如果未能解决你的问题,请参考以下文章
wp-bootstrap-nav walker 崩溃在 ipad 上不起作用
添加一个 div 并使用 wordpress walker 更改类或导航菜单?
WP 在菜单中添加属性和 HTML
php 自定义WP Nav Walker
wordpress menu-walker 中的 ACF 对象
未捕获的错误:不能将 WP_Post 类型的对象用作数组