如果我在一个部分中添加了5个以上的设置,那么设置的顺序就会变得很奇怪。
例如:
// Link color
$wp_customize->add_setting( \'tonal_\'.$themeslug.\'_settings[link_color1]\', array(
\'default\' => $themeOptions[\'link_color1\'],
\'type\' => \'option\',
\'sanitize_callback\' => \'sanitize_hex_color\',
\'capability\' => \'edit_theme_options\',
\'transport\' => \'postMessage\'
) );
$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, \'tonal_\'.$themeslug.\'_settings[link_color1]\', array(
\'label\' => __( \'Link color1\', \'tonal\' ),
\'section\' => \'colors\',
\'settings\' => \'tonal_\'.$themeslug.\'_settings[link_color1]\',
\'choices\' => \'#ffffff\'
) ) );
<支持>
Further examples in a pastebin - no expiration time颜色从1到7进行编号,但在设置中,颜色的显示顺序为:2,1,3,4,6,5,7
有没有人有过同样的经历?
或者有人知道怎么解决这个问题吗?
SO网友:kaiser
清理迭代对于调试来说要容易得多,因为您将看到逐步的信息:
»在我将这个添加到那个之后,会发生什么?«
因此,只需从清理开始,看看它是如何添加的。
foreach ( range( 1, 7 ) as $nr )
{
$wp_customize->add_setting(
"tonal_{$themeslug}_settings[link_color{$nr}]",
array(
\'default\' => $themeOptions[ "link_color{$nr}" ],
\'type\' => \'option\',
\'sanitize_callback\' => \'sanitize_hex_color\',
\'capability\' => \'edit_theme_options\',
\'transport\' => \'postMessage\'
)
);
$wp_customize->add_control(
new WP_Customize_Color_Control(
$wp_customize,
"tonal_{$themeslug}_settings[link_color{$nr}]",
array(
\'label\' => __( sprintf( \'Link color%s\', $nr ), \'tonal\' ),
\'section\' => \'colors\',
\'settings\' => "tonal_{$themeslug}_settings[link_color{$nr}]",
\'choices\' => \'#ffffff\'
)
)
);
// DEBUG:
echo \'<pre>\'; var_export( $wp_customize, true ); echo \'</pre>\';
}
排序的可能性很高,你可以通过
default php sorting mechanisms. 只需看看输出,然后看看简单的数组排序可以做什么(提示:您可以轻松地键入cast
(array) $object
和
(object) $array
.