在数组中的条件add_settings_section

问题描述 投票:0回答:1
add_settings_section( 'team_section_main', '', '', 'team_searchbox', array( 'before_section' => '<div class="tab-content" id="tab_main" style="'.$_GET['tab']=="tab_main"?"":"display:none;".'">', 'after_section' => '</div>' ) ); add_settings_section( 'team_section_destination', '', '', 'team_searchbox', array( 'before_section' => '<div class="tab-content" id="tab_destination" style="'.$_GET['tab']=="tab_destination"?"":"display:none;".'">', 'after_section' => '</div>' ) );

我有几个选项卡,并取决于选定的选项卡,我希望隐藏或显示一个DIV元素。

我似乎不正确地这样做,因为它只是输出

display:none;>
。那我想念什么?很可能是错字。

,我找到了一个解决方法。在这里回答,以添加我更新的代码。 我不再使用样式属性了,如果需要隐藏特定的选项卡,我只是添加了一个类。

$tab_main = $_GET['tab'] === 'tab_main' ? '' : 'team-hide';
$tab_dest = $_GET['tab'] === 'tab_destination' ? '' : 'team-hide';
add_settings_section(
    'team_section_main',
    '',
    '',
    'team_searchbox',
    array(
        'before_section' => '<div class="tab-content '.$tab_main.'">',
        'after_section' => '</div>'
    )
);
add_settings_section(
    'team_section_destination',
    '',
    '',
    'team_searchbox',
    array(
        'before_section' => '<div class="tab-content '.$tab_dest.'">',
        'after_section' => '</div>'
    )
);

然后仅在
php wordpress
1个回答
0
投票
类上使用CSS。 这可以解决这个技巧。

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.