什么“数组必须恰好有两个成员”?的意思
What does "array must have exactly two members" mean?
我正在尝试为我的wordpress菜单设置一个自定义步行者。它的目的是允许我将php代码添加到菜单链接中,就像我可以使用这样的文本和图像一样:
<a href="http://mcadrives.com/?ref=<?PHP code goes here?>">
我在每个超链接和图像上使用的php代码是这样的:
<a href="http://mcadrives.com/?ref=
<?php
if (!empty ( $_SERVER['QUERY_STRING'])){
echo substr($_SERVER['QUERY_STRING'],4); }
else{
echo 'mhammonds'; }
?>>
我把这个添加到我的functions.php文件中:
class Query_Nav extends Walker_Nav_Menu
{
function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
global $wp_query;
$indent = ( $depth ) ? str_repeat( "'t", $depth ) : '';
$class_names = $value = '';
$classes = empty( $item->classes ) ? array() : (array) $item->classes;
$classes[] = 'menu-item-' . $item->ID;
$class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args ) );
$class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : '';
$id = apply_filters( 'nav_menu_item_id', 'menu-item-'. $item->ID, $item, $args );
$id = $id ? ' id="' . esc_attr( $id ) . '"' : '';
$output .= $indent . '<li' . $id . $value . $class_names .'>';
$attributes = ! empty( $item->attr_title ) ? ' title="' . esc_attr( $item->attr_title ) .'"' : '';
$attributes .= ! empty( $item->target ) ? ' target="' . esc_attr( $item->target ) .'"' : '';
$attributes .= ! empty( $item->xfn ) ? ' rel="' . esc_attr( $item->xfn ) .'"' : '';
//ADD YOUR PHP HERE TO DETERMINE WHATEVER IT IS YOU NEED FOR YOUR LINK
if ( ! empty ( $_SERVER['QUERY_STRING'] ) ) {
$addedStuff = '?ref=' . substr( $_SERVER['QUERY_STRING'], 4 );
}else {
$addedStuff = '?ref=mhammonds';
}
$attributes .= ! empty( $item->url ) ? ' href="' . esc_attr( $item->url.$addedStuff) .'"' : '';
////////////////////
$item_output = $args->before;
$item_output .= '<a'. $attributes .'>';
$item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;
$item_output .= '</a>';
$item_output .= $args->after;
$output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
}
}
,我添加了这个walker 'new Query_Nav'到我的nav_menu -template.php:
function wp_nav_menu( $args = array() ) {
static $menu_id_slugs = array();
$defaults = array( 'menu' => '', 'container' => 'div', 'container_class' => '', 'container_id' => '', 'menu_class' => 'menu', 'menu_id' => '',
'echo' => true, 'fallback_cb' => 'wp_page_menu', 'before' => '', 'after' => '', 'link_before' => '', 'link_after' => '', 'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>',
'depth' => 0, 'walker' => 'new Query_Nav()', 'theme_location' => '' );
然后我被一个警告通知,类'new Query_Nav()'没有在第660行找到,所以我像这样添加它:
function walk_nav_menu_tree( $items, $depth, $r ) {
$walker = ( empty($r->walker) ) ? new Walker_Nav_Menu : $r->walker;
$args = array( $items, $depth, $r );
return call_user_func_array( array( $walker, 'walk', 'new Query_Nav()'), $args );
现在我有另一个警告声明:
call_user_func_array() expects parameter 1 to be a valid callback, array must have exactly two members in /home/ballaboy258/public_html/wp-includes/nav-menu-template.php on line 660
我把它们都去掉了,但都没有解决问题。如果我删除$walker,那么'walk'就找不到。如果我删除'walk',则找不到'new Query_Nav()'。如果我删除'new Query_Nav()',再次,'new Query_Nav()'没有找到。这没有任何意义。是我漏了一步,还是我的语法错了?我很困惑,我在网上找不到任何东西来帮助我。
这意味着你的回调数组
array( $walker, 'walk', 'new Query_Nav()'),
应该包含两个元素
- 类
表示要调用的函数
您已经提供了三个
相关文章:
- JQuery合并了keyup和focusout两个函数
- 如何使用 node.js 比较两个 json 数组
- 为复选框javascript指定两个值
- 用每小时的差值填充数组/列表-从下拉列表中给定两个时间值
- 单击时切换两个图像
- 我可以'我似乎不知道如何修复javascript中的两个lint.有人能帮我理解吗
- 基于两个条件退出While循环
- 如何在这里将两个值最低的数字相加
- 组合两个javascript函数
- 如何使用offer/answer交换来自两个对等连接的流
- jsf中两个字符串的颜色代码差异
- 加载两个具有相同父密钥名称的json文件
- 在Qualtrics中,介绍如何动态连接两个滑块
- 访问$.ajax()函数中的两个不同数组
- 如何在three.js上添加两个向量
- 如何在datetimepicker中使用两个验证器
- 如何在javascript中获取两个日期之间的周六和周日的日期
- 两个指令创建新的继承的和隔离的作用域-元素得到哪个
- javascript函数,它接受两个输入:一个对象和一个键,并返回对象中该键的相应值
- 什么“数组必须恰好有两个成员”?的意思