小编Roo*_*Roo的帖子

更优雅的方法来删除中间阵列?

所以有这个"美丽的"多维数组:

array 
  0 => 
    array 
      0 => 
        object(SimpleXMLElement)
          public 'name' => string 'some name'
          public 'model' => string 'some model'
      1 => 
        object(SimpleXMLElement)
          public 'name' => string 'some name'
          public 'model' => string 'some model'
  1 => 
    array 
      0 => 
        object(SimpleXMLElement)
          public 'name' => string 'some name'
          public 'model' => string 'some model'
      1 => 
        object(SimpleXMLElement)
          public 'name' => string 'some name'
          public 'model' => string 'some model'

and so on
Run Code Online (Sandbox Code Playgroud)

我删除了中间数组以获得一个带循环(并将对象转换为数组):

foreach ($items as $x) {
    foreach ($x as …
Run Code Online (Sandbox Code Playgroud)

php arrays

5
推荐指数
1
解决办法
89
查看次数

将自定义 <li> 添加到 Wordpress 导航菜单

我只是无法完全理解自定义步行者如何在 worpress 中工作:

主题的 home.php 中的代码(实际上所有代码都包含在其他文件中,以免弄乱 HTML)如下所示:

/**
 * Contains wordpress function with array with parameters
 * @return string HTML output
 */
function show_main_navigation() {
    return wp_nav_menu(
        array(
            'theme_location' => 'header-menu',
            'echo' => false,
            'depth' => '-1',
            'walker' => new Last_Item_Walker()
        )
    );
}
Run Code Online (Sandbox Code Playgroud)

沃克看起来像这样:

class Last_Item_Walker extends Walker_Nav_Menu { 

    function end_lvl( &$output, $depth = 0, $args = array() ) {
        $indent = str_repeat("\t", $depth);
        $output .= '<li class="spec"><a href="#" title="title">title</a></li>'; // my custom <li>
        $output .= "$indent</ul>\n";
    }
} …
Run Code Online (Sandbox Code Playgroud)

php wordpress

1
推荐指数
1
解决办法
5990
查看次数

标签 统计

php ×2

arrays ×1

wordpress ×1