我正在使用带有Xprofile插件的BuddyPress。
个人资料中的字符串是出生日期,我希望它在个人资料页面输出上显示年龄。
这是默认代码,它将显示配置文件字段名称,然后显示该字段的值。
<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>
我希望它有一个例外,如果一个名为&#34的字符串;出生日期&#34;出现在bp_the_profile_field_name(); ,然后它会显示字符串&#34;年龄&#34;相反,但显示其余字段与它们相同。
答案 0 :(得分:1)
如评论中所述,您应该能够看到函数bp_get_the_profile_field_name()
是否返回字符串'出生日期',然后做适当的事情。
使用if / else块的示例:
if (bp_get_the_profile_field_name() == 'Date of Birth') {
print 'Age';
} else {
print bp_get_the_profile_field_name();
}
或通过三元运算符(if / else的简写):
<?php print bp_get_the_profile_field_name() ? 'Age' : bp_get_the_profile_field_name(); ?>