我正在尝试更改我网站上导航的标记,我对开发wordpress非常陌生,但我遇到了显示我的Walker类的问题。我正在尝试重新配置Wordpress附带的2017主题。但是我一直收到这样的错误,上面写着“致命错误:Class'Walker_Nav_Primary'在第56行的/wp-content/themes/Vibe/header.php中找不到”这就是这个类的样子:
<?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 .= "\n$indent<ul class=\"dropdown-menu$submenu depth_$depth\">\n";
}
/*
function start_el( ){ //li a span
}
function end_el(){ // closing li a span
}
function end_lvl(){ // closing ul
}
*/
}
我的头文件中我称之为的部分:
<?php wp_nav_menu( array(
'theme_location' => 'top',
'menu_id' => 'primary-menu',
'menu_class' => 'head-menu',
'walker' => new Walker_Nav_Primary(),
) ); ?>
编辑:
// This theme uses wp_nav_menu() in two locations.
register_nav_menus( array(
'top' => __( 'Top Menu', 'twentyseventeen' ),
'social' => __( 'Social Links Menu', 'twentyseventeen' ),
) );
答案 0 :(得分:0)
也许需要工作,在标题php文件中
require_once('xxx/xxx/Walker_Nav_Primary.php');
答案 1 :(得分:0)
将他放入你的functions.php文件
// Register Custom Navigation Walker
require_once get_template_directory() . '/walker-fie-name.php';
尝试此操作并在有任何问题时予以回复。
在你的情况下,它应该是
require_once get_template_directory() . '/inc/walker.php';
使用此代码更新walker.php文件
<?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 .= "\n$indent<ul class=\"dropdown-menu$submenu depth_$depth\">\n";
}
}
将power.php文件置于最顶层
替换
require_once get_template_directory() . '/inc/walker.php';
使用此代码。
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 :(得分:0)
我认为您应该更改此代码!
<?php wp_nav_menu( array(
'theme_location' => 'top',
'menu_id' => 'primary-menu',
'menu_class' => 'head-menu',
'walker' => new Walker_Nav_Primary(),) ); ?>
到此:
<?php
$walker = new Walker_Nav_Primary;
wp_nav_menu( array(
'theme_location' => 'top',
'menu_id' => 'primary-menu',
'menu_class' => 'head-menu',
'walker' => $walker,) ); ?>