Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 插入<;部门>;内纳沃克_Php_Wordpress_Wp Nav Walker - Fatal编程技术网

Php 插入<;部门>;内纳沃克

Php 插入<;部门>;内纳沃克,php,wordpress,wp-nav-walker,Php,Wordpress,Wp Nav Walker,所以我遇到了一些问题,我不知道如何解决它们,我最近开始与WordPress navwalkers合作,我被困在一个特定的问题上,我不知道如何解决它 所以我在wordpress主题中使用了Bulma框架 以下是我试图实现的目标(如果您有任何批评,请给我批评,我仍在学习)-我只是不知道如何在第一个$depth之后添加额外的div进行包装: 这是我的wp\u导航菜单标题: <div class="container"> <div clas

所以我遇到了一些问题,我不知道如何解决它们,我最近开始与
WordPress navwalkers
合作,我被困在一个特定的问题上,我不知道如何解决它

所以我在wordpress主题中使用了Bulma框架

以下是我试图实现的目标(如果您有任何批评,请给我批评,我仍在学习)-我只是不知道如何在第一个
$depth
之后添加额外的div进行包装:

这是我的
wp\u导航菜单
标题:

<div class="container">
            <div class="navbar-menu is-active">
                    <div class="navbar-start" id="main-navigation">
                        <?php
                        wp_nav_menu( [
                            'theme_location' => 'primary',
                            'depth' => 3,
                            'container' => true,
                            'items_wrap' => '%3$s', // Removes the <ul>
                            'walker' => new Nav_walker(),
                        ]);
                        ?>
                    </div>

                <div class="navbar-end">
                    <div class="navbar-item">
                        <figure class="image is-48x48">
                            <img class="is-rounded" src="<?php if (is_user_logged_in()) {
                                $current_user = wp_get_current_user();
                                if (($current_user instanceof WP_User)) {
                                    echo get_avatar_url($current_user->ID, 32);
                                }
                            } ?>" alt="profile picture">
                        </figure>
                        <div class="pl-2"><?= $user->get_user_login(); ?></div>
                    </div>
                </div>
            </div>
        </div>

ID,32);
}
}?>“alt=”个人资料图片“>
这是navwalker代码

class Nav_walker extends Walker_Nav_Menu {

    public function start_lvl(&$output, $depth = 0, $args = []) {

        // Indent the items
        $indent = str_repeat("\t", $depth);

        // The first <div> inside mega-menu
        if ($depth == 0) {
            $output .= "<div class=\"navbar-dropdown\">";
        } else {
            $output .= "<div id=\"test\">";
        }
    }

    public function start_el(&$output, $item, $depth = 0, $args = [], $id = 0) {

        $all_classes = implode(' ', $item->classes); // turn the WP classes object array to string values

        if ($depth == 1) {
            $liClasses = 'navbar-item column is-3' . $all_classes; // add the values to your classes list
        } else {
            $liClasses = 'navbar-item ' . $all_classes;
        }

        // If menu it has children
        $hasChildren = $args->walker->has_children;

        if ($depth === 0) {
            $liClasses .= $hasChildren ? " has-dropdown is-hoverable": "";
        }

        if ($hasChildren) {
            $output .= "<div class='" . $liClasses . "'>";

            if ($depth === 0) {
                $output .= "<div class='navbar-link'>" . $item->title . "</div>";
            } else {
                $output .= "<h1 class='title is-6 is-mega-menu-title'>" . $item->title . "</h1>";
            }
        }
        else {
            $output .= "<a class='navbar-item' href='" . $item->url . "'>" . $item->title;
        }

        // Adds has_children class to the item so end_el can determine if the current element has children
        if ($hasChildren) {
            $item->classes[] = 'has_children';
        }
    }

    public function end_el(&$output, $item, $depth = 0, $args = array(), $id = 0 ){

        if (in_array("has_children", $item->classes)) {
            $output .= "</div>";
        }
        $output .= "</a>";
    }

    public function end_lvl (&$output, $depth = 0, $args = array()) {

        $output .= "</div>";
    }
}
class-Nav\u-walker扩展了walker\u-Nav\u菜单{
公共函数start_lvl(&$output,$depth=0,$args=[])){
//缩进项目
$indent=str\u repeat(“\t”,$depth);
//第一个内部大菜单
如果($depth==0){
$output.=“”;
}否则{
$output.=“”;
}
}
公共函数start_el(&$output,$item,$depth=0,$args=[],$id=0){
$all_classes=内爆(“”,$item->classes);//将WP classes对象数组转换为字符串值
如果($depth==1){
$liClasses='navbar项列为-3'。$all_classes;//将值添加到类列表中
}否则{
$liClasses='navbar项'.$all_类;
}
//如果它有子菜单
$haschilds=$args->walker->has\u children;
如果($depth==0){
$liClasses.=$hasChildren?“has下拉列表可悬停”:“;
}
如果(有子女){
$output.=“”;
如果($depth==0){
$output.=''.$item->title.'';
}否则{
$output.=''.$item->title.'';
}
}
否则{
$output.=“”;
}
公共函数end_lvl(&$output,$depth=0,$args=array()){
$output.=“”;
}
}