-1

如果“total_of_groups”不为 0,我想将以下选项添加到现有的选择框中。

 <option value="groupmembers" <?php echo selected('groupmembers',bp_profile_visibility_get_settings($user_id,'bp_profile_visibility' ));?>><?php _e('Group Members Only','bp-profile-visibility');?></option>

不幸的是,它不起作用。我已经在选择之外测试了代码片段,它运行良好。

            <select  name="bp_profile_visibility">
                <option value="public" <?php echo selected('public',bp_profile_visibility_get_settings($user_id,'bp_profile_visibility' ));?>><?php _e('Everyone','bp-profile-visibility');?></option>    
                <option value="friends" <?php echo selected('friends',bp_profile_visibility_get_settings($user_id,'bp_profile_visibility' ));?>><?php _e('Friends Only','bp-profile-visibility');?></option>    
                    // the new option //
                    <?php
                    $is_groupmember = BP_Groups_Member::get_group_ids( bp_displayed_user_id() );
                    $total_of_groups = $is_groupmember[total];
                    if( $total_of_groups != 0 )             
                         echo <option value="groupmembers" <?php echo selected('groupmembers',bp_profile_visibility_get_settings($user_id,'bp_profile_visibility' ));?>><?php _e('Group Members Only','bp-profile-visibility');?></option>
                    ?>                  
                <option value="self" <?php echo selected('self',bp_profile_visibility_get_settings($user_id,'bp_profile_visibility' ));?>><?php _e('Only Me (private)','bp-profile-visibility');?></option>    
            </select> 
4

2 回答 2

0

好的,我自己找到了解决方案:

翻译部分必须以“__”开头,而不是“_e”。

echo '<option value="groupmembers" ' . selected('groupmembers',bp_profile_visibility_get_settings($user_id,'bp_profile_visibility' )) . '>' . __('Group Members Only','bp-profile-visibility') . '</option>';                    ?>                  
于 2013-08-26T22:04:28.083 回答
0

您没有在echo语句周围加上引号,并且您已经在 php 块中。尝试这个:

if( $total_of_groups != 0 )             
    echo '<option value="groupmembers" ' . selected('groupmembers',bp_profile_visibility_get_settings($user_id,'bp_profile_visibility' )); . '>' . _e('Group Members Only','bp-profile-visibility') . '</option>';
于 2013-08-26T20:40:34.403 回答