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条)

报告相同问题?

悬赏问题

  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题