我来自Javascript背景,谦恭地跳进了WP开发,在PHP方面遇到了一些问题(尤其是在WordPress上下文中)。
Here\'s what I\'m trying to do:
从数组中为自定义程序创建控件;具体来说,社交图标url输入用于大量社交网站。
Here\'s what I\'ve tried (and isn\'t working):
$socialIcons = array (
array( \'name\' => \'behance\', \'label\' => \'Behance URL\' ),
array( \'name\' => \'bitbucket\', \'label\' => \'BitBucket URL\' ),
array( \'name\' => \'digg\', \'label\' => \'Digg URL\' ),
array( \'name\' => \'dribble\', \'label\' => \'Dribble URL\' ),
array( \'name\' => \'facebook\', \'label\' => \'Facebook URL\' ),
array( \'name\' => \'flickr\', \'label\' => \'Flickr URL\' ),
array( \'name\' => \'forest\', \'label\' => \'Forest URL\' ),
array( \'name\' => \'github\', \'label\' => \'GitHub URL\' ),
array( \'name\' => \'gplus\', \'label\' => \'Google Plus URL\' ),
array( \'name\' => \'instagram\', \'label\' => \'Instagram URL\' ),
array( \'name\' => \'lastfm\', \'label\' => \'Lastfm URL\' ),
array( \'name\' => \'linkedin\', \'label\' => \'LinkedIn URL\' ),
array( \'name\' => \'pintrest\', \'label\' => \'Pintrest URL\' ),
array( \'name\' => \'reddit\', \'label\' => \'Reddit URL\' ),
array( \'name\' => \'soundcloud\', \'label\' => \'SoundCloud URL\' ),
array( \'name\' => \'stackexchange\', \'label\' => \'StackExchange URL\' ),
array( \'name\' => \'stackoverflow\', \'label\' => \'StackOverflow URL\' ),
array( \'name\' => \'twitter\', \'label\' => \'Twitter URL\' ),
array( \'name\' => \'vimeo\', \'label\' => \'Vimeo URL\' ),
array( \'name\' => \'vk\', \'label\' => \'VK URL\' ),
array( \'name\' => \'youtube\', \'label\' => \'YouTube URL\' ),
);
$i = 0;
foreach ($socialIcons as $icon) {
$i = $i++
$wp_customize->add_setting(
\'pxk_href_\' . $icon[\'name\'], // use this in twig file call to theme_mod
array(
\'default\' => \'\',
\'transport\' => \'postMessage\',
\'priority\' => $i
)
);
$wp_customize->add_control(
new WP_Customize_Control(
$wp_customize,
\'custom_href_\' . $icon[\'name\'],
array(
\'label\' => __( $icon[\'label\'], \'pxk\' ),
\'section\' => \'social\',
\'settings\' => \'pxk_href_\' . $icon[\'name\'],
\'type\' => \'url\',
\'input_attrs\' => array(
\'placeholder\' => \'http://your \' . $icon[\'name\']
),
)
)
);
};
这会引发PHP语法分析错误,声明
unexpected \'$wp_customize\' (T_VARIABLE)...
我怀疑我需要将其组织成一个或两个函数,返回或回显$wp_
arrow函数,并且可能会以不同的方式调用它,以便成功地为数组的每个项创建设置和控件。想法?
非常感谢您的任何反馈/帮助:)