duanlu1876 2017-09-28 05:36
浏览 48
已采纳

致命错误:未找到“Walker_Nav_Primary”类

I am trying to change the markup for the nav on my site and I am pretty new to developing wordpress, but I am having issues getting it to display my Walker class. I am attempting to reconfigure the 2017 theme that comes with Wordpress. But I keep getting this error that says "Fatal error: Class 'Walker_Nav_Primary' not found in /wp-content/themes/Vibe/header.php on line 56" This is what the class looks like:

<?php
  class Walker_Nav_Primary extends Walker_Nav_menu {

    function start_lvl( &$output, $depth = 0, $args = array() ){ //ul
        $indent = str_repeat("\t",$depth);
        $submenu = ($depth > 0) ? ' sub-menu' : '';
        $output .= "
$indent<ul class=\"dropdown-menu$submenu depth_$depth\">
";
    }
    /*  
    function start_el( ){ //li a span
    }
    function end_el(){ // closing li a span
    }

    function end_lvl(){ // closing ul

    }
    */
     }

And the portion of my header file where I am calling it:

<?php wp_nav_menu( array(
    'theme_location' => 'top',
    'menu_id'        => 'primary-menu',
    'menu_class'        => 'head-menu',
    'walker'            =>  new Walker_Nav_Primary(),
) ); ?>

EDIT:

// This theme uses wp_nav_menu() in two locations.
register_nav_menus( array(
    'top'    => __( 'Top Menu', 'twentyseventeen' ),
    'social' => __( 'Social Links Menu', 'twentyseventeen' ),
) );
  • 写回答

3条回答 默认 最新

  • dongluxin2452 2017-09-28 06:06
    关注

    Put his in your functions.php file

    // Register Custom Navigation Walker
    require_once get_template_directory() . '/walker-fie-name.php';
    

    Try this and reply if any issue.

    In your case, it should be

    require_once get_template_directory() . '/inc/walker.php';
    

    Update you walker.php file with this code

    <?php
    if ( ! class_exists( 'Walker_Nav_Primary' ) ) {
      class Walker_Nav_Primary extends Walker_Nav_menu {
    
        public function start_lvl( &$output, $depth = 0, $args = array() ){ //ul
            $indent = str_repeat("\t",$depth);
            $submenu = ($depth > 0) ? ' sub-menu' : '';
            $output .= "
    $indent<ul class=\"dropdown-menu$submenu depth_$depth\">
    ";
        }
    }
    

    Put in function.php file at very top

    Replace

    require_once get_template_directory() . '/inc/walker.php';
    

    With this code.

    if ( ! file_exists( get_template_directory() . '/inc/walker.php' ) ) {
        // file does not exist... return an empty page with msg not found
        wp_die('Not found');
    } else {
        // file exists... require it.
        require_once get_template_directory() . '/inc/walker.php';
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)