尝试替换PHP字符串以显示不同的输出

尝试替换PHP字符串以显示不同的输出,php,wordpress,buddypress,Php,Wordpress,Buddypress,我正在使用BuddyPress和Xprofile插件 配置文件中的字符串是出生日期,我希望它在配置文件页面输出中显示年龄 这是默认代码,它将显示配置文件字段名称,然后显示该字段的值 <dl<?php bp_field_css_class('dl-horizontal'); ?>> <dt><?php bp_the_profile_field_name(); ?></dt> <d

我正在使用BuddyPress和Xprofile插件

配置文件中的字符串是出生日期,我希望它在配置文件页面输出中显示年龄

这是默认代码,它将显示配置文件字段名称,然后显示该字段的值

 <dl<?php bp_field_css_class('dl-horizontal'); ?>>

            <dt><?php bp_the_profile_field_name(); ?></dt>

            <dd><?php bp_the_profile_field_value(); ?></dd>
          </dl>


我希望它有一个例外,如果一个名为“Date of Birth”的字符串出现在bp_profile_字段_name()中,然后,它将显示字符串“Age”,但其余字段的显示与它们相同。

如注释中所述,您应该能够看到函数
bp\u get\u the_profile\u field\u name()
是否返回字符串“Date of Birth”,然后执行适当的操作

使用if/else块的示例:

if (bp_get_the_profile_field_name() == 'Date of Birth') {
    print 'Age';
} else {
    print bp_get_the_profile_field_name();
}
或通过三元运算符(if/else的缩写):



您想将字符串
“出生日期”
更改为字符串
“年龄”
,或者至少以这种方式显示它?我不熟悉buddypress,但一般来说,检查字符串是否是一个东西,是否显示其他东西是相当简单的。甚至是这样的:
bp\u获取\u profile\u字段\u name()=“出生日期”?”年龄:bp_get_the_profile_field_name()
我编辑了我的帖子,让它更清晰一点,我尝试了你的代码,它不起作用;没有显示任何字段。。。我对PHP非常陌生:(我不知道这个buddycode,但一般来说,你需要在一个更大的PHP代码插入中生成html/xml(dl、dt等标记)和好友代码,以便有条件地创建好友标记。例如:生成html,如果我的字符串等于……那么生成这些好友标记,否则。
<?php print bp_get_the_profile_field_name() ? 'Age' : bp_get_the_profile_field_name(); ?>