我尝试将WordPress主题选项从SMOF传输到Redux Framework,因为不再维护SMOF。我已经成功转移了所有其他选项并且它们完美地工作但我在上下文中遇到了这个错误:
Parse error: syntax error, unexpected 'foreach' (T_FOREACH), expecting ')'
旧代码用于使用"type" => "text"
创建内置翻译器选项,并且工作得很好但是我不知道如何在新的Redux Framework中实现它以运行并且不再出现此错误
以下是SMOF框架中的旧代码:
$translate_strings = theme_get_translate_options();
foreach ( $translate_strings as $string_key => $string ) {
$of_options[] = array( "name" => esc_html( $string['string_text'] ),
"id" => 'td_'.$string_key,
"type" => "text",
);
}
这是Redux Framework的新界面。应该在哪里使用:"type" => "text",
:
$translate_strings = theme_get_translate_options();
// -> START Translation Info Fields
Redux::setSection( $opt_name, array(
'title' => __( 'Translator', 'redux-framework-demo' ),
'desc' => __( '', 'redux-framework-demo' ),
'id' => 'translator-info-subsection',
'subsection' => true,
'fields' => array(
array(
'id' => '',
'type' => 'text',
'title' => __( '', 'redux-framework-demo' ),
'desc' => __( '', 'redux-framework-demo' ),
),
)
) );
我使用并发生错误的代码如下:
$translate_strings = theme_get_translate_options();
Redux::setSection( $opt_name, array(
'title' => __( 'Translator', 'redux-framework-demo' ),
'desc' => __( '', 'redux-framework-demo' ),
'id' => 'translator-info-subsection',
'subsection' => true,
'fields' => array(
foreach ( $translate_strings as $string_key => $string ) {
array(
'id' => 'td_'.$string_key,
'type' => 'text',
'title' => __( '', 'redux-framework-demo' ),
),
}
)
) );
我完全坚持这一点,任何帮助或建议将不胜感激。
谢谢!
答案 0 :(得分:0)
稍微重组就足够了:
$translate_strings = theme_get_translate_options();
$myFields = array();
foreach ( $translate_strings as $string_key => $string ) {
$myFields[]=
array(
'id' => 'td_'.$string_key,
'type' => 'text',
'title' => __( '', 'redux-framework-demo' ),
);
}
Redux::setSection( $opt_name, array(
'title' => __( 'Translator', 'redux-framework-demo' ),
'desc' => __( '', 'redux-framework-demo' ),
'id' => 'translator-info-subsection',
'subsection' => true,
'fields' => $myFields
) );
我从初始化中取出foreach
并分别初始化了array
。