dt2002 2014-03-06 09:41
浏览 5
已采纳

WordPress导航助行器功能的Stric标准错误

The themeforest support tell me that I have this two errors in a WordPress theme: this and this.

This is the wp_nav_menu walker function:

class description_walker extends Walker_Nav_Menu
{

  function start_el(&$output, $item, $depth, $args )
  {
       global $wp_query;
       $indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';

       $class_names = $value = '';

       $classes = empty( $item->classes ) ? array() : (array) $item->classes;

       $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) );
       $class_names = ' class="'. esc_attr( $class_names ) . '"';

       $output .= $indent . '<li id="menu-item-'. $item->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        ) .'"' : '';
       $attributes .= ! empty( $item->url )        ? ' href="'   . esc_attr( $item->url        ) .'"' : '';

       if($depth != 0)
       {
                 $description = $append = $prepend = "";
       }

        $item_output = $args->before;
        $item_output .= '<a'. $attributes .' class="external">';
        $item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID );
        $item_output .= '</a>';
        $item_output .= $args->after;

        $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );

                    if ($item->menu_order == 1) {
            $classes[] = 'first';
        }

        }
}

The problem is that my WordPress doesnt show this errors. I have WordPress 3.8.1 and I haveWP_DEBUG` set to true.

The first error seems to fixed changing this line: function start_el(&$output, $item, $depth = 0, $args = array(), $id = 0). The second error I have change $item_output = $args->before; to $item_output = $args['before']; But this cause an error:

Fatal error: Cannot use object of type stdClass as array in /home/codetoco/public_html/wp-content/themes/quins/functions.php on line 338

Why are they getting an error an me not? How can I fix this errors?

  • 写回答

1条回答 默认 最新

  • doushansu9012 2014-03-06 09:47
    关注

    The second error I have change $item_output = $args->before; to $item_output = $args['before']; But this cause an error:

    Fatal error: Cannot use object of type stdClass as array in /home/codetoco/public_html/wp-content/themes/quins/functions.php on line 338

    Its because $args is an object and not an array so you need to use the -> instead of []

    You might also want to check out this to find more about enabling error reporting in PHP. It really helps to enable error reporting during development as it immediately informs you when you do something wrong. But be sure to disable it when you push your code to a live server as this can be a potential cause for leaking information that you don't want the outside world to know.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
  • ¥15 C#调用python代码(python带有库)
  • ¥15 矩阵加法的规则是两个矩阵中对应位置的数的绝对值进行加和
  • ¥15 活动选择题。最多可以参加几个项目?
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)
  • ¥20 怎么在stm32门禁成品上增加查询记录功能
  • ¥15 Source insight编写代码后使用CCS5.2版本import之后,代码跳到注释行里面