如果'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之外测试了代码片段,它完美无缺。
<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>
答案 0 :(得分: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>';
答案 1 :(得分:0)
o.k。我自己找到了解决方案:
翻译部分必须以“__”开头,而不是“_e”。
echo '<option value="groupmembers" ' . selected('groupmembers',bp_profile_visibility_get_settings($user_id,'bp_profile_visibility' )) . '>' . __('Group Members Only','bp-profile-visibility') . '</option>'; ?>