使用wordpress并查看代码示例,我已经看到了使用数组和函数的两种不同方式:
1.首先定义数组,然后将其作为参数传递给函数
$args = array(
'name' => 'Home right sidebar',
'id' => 'home_right_1',
'before_widget' => '<div>',
'after_widget' => '</div>',
'before_title' => '<h2 class="rounded">',
'after_title' => '</h2>',
);
register_sidebar( $args );
register_sidebar( array(
'name' => 'Home right sidebar',
'id' => 'home_right_1',
'before_widget' => '<div>',
'after_widget' => '</div>',
'before_title' => '<h2 class="rounded">',
'after_title' => '</h2>',
) );
将数组定义为函数调用(#2)的一部分是不好的做法,还是它是一种样式选择?
如果不好的做法,为什么呢?
解决方法:
不,这不是坏习惯.
如果要重复使用阵列,则必须选择第一个可能性.否则,选择取决于您.