【发布时间】:2015-08-18 17:02:12
【问题描述】:
所以我目前正在创建一个站点选项插件。我想在设置部分之间添加选项卡功能,但我不想为每个选项卡设置单独的页面(就像我在大多数教程中看到的那样,我认为这是因为随机数)。我希望只有一个简单的 jQuery Tab 功能。
因此,为了做到这一点,我需要在每个设置部分周围包裹一个 div。似乎没有办法挂钩 do_settings_sections 或 add_setting_section wordpress 函数。
所以我的解决方案就是在我的插件中复制 do_settings_sections 函数并添加我需要的内容。这样做是不是很傻,下次更新 WordPress 会不会遇到问题?
这是我的新 do_settings_section 函数(在我的插件中调用)
function do_settings_sections_new( $page ) {
global $wp_settings_sections, $wp_settings_fields;
if ( ! isset( $wp_settings_sections[$page] ) )
return;
$numCategory=0; //Added by me
foreach ( (array) $wp_settings_sections[$page] as $section ) {
$numCategory++;//Added by me
if ( $section['title'] )
echo "<div class='opt-category active' data-content=". $numCategory .">"; //Added by me
echo "<h3>{$section['title']}</h3>\n";
if ( $section['callback'] )
call_user_func( $section['callback'], $section );
if ( ! isset( $wp_settings_fields ) || !isset( $wp_settings_fields[$page] ) || !isset( $wp_settings_fields[$page][$section['id']] ) )
continue;
echo '<table class="form-table2">';
do_settings_fields( $page, $section['id'] );
echo '</table>';
echo '</div>'; //Added by me
}
}
【问题讨论】:
标签: wordpress