wir*_*s-g 1 php wordpress redux-framework
我正在使用一个wordpress主题,它有自己的框架,它基于我认为的redux框架.我正在使用子主题修改此主题.我想在后端添加主题选项,我在父主题的文件中找到了一个似乎正是我需要的函数:
/*
*
* Custom function for filtering the sections array. Good for child themes to override or add to the sections.
* Simply include this function in the child themes functions.php file.
*
* NOTE: the defined constansts for URLs, and directories will NOT be available at this point in a child theme,
* so you must use get_template_directory_uri() if you want to use any of the built in icons
*
*/
function add_another_section($sections){
//$sections = array();
$sections[] = array(
'title' => __('A Section added by hook', 'swift-framework-admin'),
'desc' => __('<p class="description">This is a section created by adding a filter to the sections array. Can be used by child themes to add/remove sections from the options.</p>', 'swift-framework-admin'),
// Redux ships with the glyphicons free icon pack, included in the options folder.
// Feel free to use them, add your own icons, or leave this blank for the default.
'icon' => trailingslashit(get_template_directory_uri()) . 'options/img/icons/glyphicons_062_attach.png',
// Leave this as a blank section, no options just some intro text set above.
'fields' => array()
);
return $sections;
}
//add_filter('redux-opts-sections-twenty_eleven', 'add_another_section');
Run Code Online (Sandbox Code Playgroud)
我已将此函数添加到我的子主题的functions.php中,并取消注释add_filter.但是,这似乎不起作用,并且没有添加新的部分.
我在其他地方遇到了这个讨论,这表明函数的名称需要改变(我得到了同样的错误).我已经做到了,它仍然无法正常工作.
这是我在我的孩子主题functions.php中的内容
function add_another_section_bl($sections){
$sections = array();
$sections[] = array(
'title' => __('A Section added by hook', 'swift-framework-admin'),
'desc' => __('<p class="description">This is a section created by adding a filter to the sections array. Can be used by child themes to add/remove sections from the options.</p>', 'swift-framework-admin'),
// Redux ships with the glyphicons free icon pack, included in the options folder.
// Feel free to use them, add your own icons, or leave this blank for the default.
'icon' => trailingslashit(get_template_directory_uri()) . 'options/img/icons/glyphicons_062_attach.png',
// Leave this as a blank section, no options just some intro text set above.
'fields' => array()
);
return $sections;
}
add_filter('redux-opts-sections-twenty_eleven', 'add_another_section_bl');
Run Code Online (Sandbox Code Playgroud)
我不确定过滤器名称'redux-opts-sections-twenty_eleven'是否需要编辑,因为它提到了二十一个主题.我最后用不同的主题名称尝试了它,而不是二十二十一,这没有任何效果.
任何帮助将不胜感激!在旁注中,我已经能够通过将整个framwork文件夹复制到我的子主题并在子主题的functions.php中定义框架的路径来完成向主题选项添加新选项.我觉得应该有一个更加光滑,更整洁的方式来实现这一点,我认为这个功能听起来很完美.
非常感谢.
Dov*_*ovy 10
这里是Redux Framework的领导开发者.此解决方案仅在您使用Redux Framework 3.1+时才有效.如果您有旧版本,请安装Redux Framework插件,它将覆盖主题中的版本.
首先转到当前选项面板.打开一个javascript控制台(使用chrome或firefox)并输入:redux.args.opt_name.那将是一个名字.将其复制并粘贴到此函数中,替换OPT_NAME为echo out的名称:
function add_another_section_bl($sections){
$sections = array(); // Delete this if you want to keep original sections!
$sections[] = array(
'title' => __('A Section added by hook', 'swift-framework-admin'),
'desc' => __('<p class="description">This is a section created by adding a filter to the sections array. Can be used by child themes to add/remove sections from the options.</p>', 'swift-framework-admin'),
// Redux ships with the glyphicons free icon pack, included in the options folder.
// Feel free to use them, add your own icons, or leave this blank for the default.
'icon' => trailingslashit(get_template_directory_uri()) . 'options/img/icons/glyphicons_062_attach.png',
// Leave this as a blank section, no options just some intro text set above.
'fields' => array()
);
return $sections;
}
// In this example OPT_NAME is the returned opt_name.
add_filter("redux/options/OPT_NAME/sections", 'add_another_section_bl');
Run Code Online (Sandbox Code Playgroud)
祝好运!
**更新**
使用Redux API,您可以轻松地添加新的部分.
Redux::addSection(array(
'title' => __('A Section added by hook', 'swift-framework-admin'),
'desc' => __('<p class="description">This is a section created by adding a filter to the sections array. Can be used by child themes to add/remove sections from the options.</p>', 'swift-framework-admin'),
// Redux ships with the glyphicons free icon pack, included in the options folder.
// Feel free to use them, add your own icons, or leave this blank for the default.
'icon' => trailingslashit(get_template_directory_uri()) . 'options/img/icons/glyphicons_062_attach.png',
// Leave this as a blank section, no options just some intro text set above.
'fields' => array()
))
Run Code Online (Sandbox Code Playgroud)
这使得使用我们的API更容易一点我相信我们在Redux 3.2中发布了...