MyBB Community Forums

Full Version: Replace display of username with custom field
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi there,

I have created a custom field called friendly name which users create on sign-up. The reason for this is that we want to display users real names instead of usernames, and its likely we will thus have people with the same name (like facebook).

All working good so far.

So wherever the username is usually displayed (posts, comments etc, members list etc) I want to display the friendly name custom field instead of the username.

What's the best way to achieve this?

Please note this doesnt affect login as we have already built a SSO component which is working well.

Your help greatly appreciated.

D
Hey guys,

What are your thoughts on the best way to do this?
I've edited postbit, but not other templates. If you haven't edited your postbit template, replace it with this.

{$ignore_bit}
<a name="pid{$post['pid']}" id="pid{$post['pid']}"></a>
<table border="0" cellspacing="{$theme['borderwidth']}" cellpadding="{$theme['tablespace']}" class="tborder" style="{$post_extra_style} {$post_visibility}" id="post_{$post['pid']}">
	<tbody>
		<tr>
			<td class="tcat">
				<div class="float_left smalltext">
					{$post['postdate']}, {$post['posttime']} <span id="edited_by_{$post['pid']}">{$post['editedmsg']}</span>
				</div>
				{$post['posturl']}
			</td>
		</tr>

		<tr>
			<td class="trow1 {$unapproved_shade}">
				<table cellspacing="0" cellpadding="0" border="0" style="width: 100%;">
					<tr>
						<td class="post_avatar" width="1" style="{$post['avatar_padding']}">
							{$post['useravatar']}
						</td>
						<td class="post_author">
							<strong><span class="largetext">{$post['fid4']}</span></strong> {$post['onlinestatus']} (<a href="member.php?action=profile&uid={$post['uid']}">My Profile</a>)<br />
							<span class="smalltext">
								{$post['usertitle']}<br />
								{$post['userstars']}
								{$post['groupimage']}
							</span>
						</td>
						<td class="smalltext post_author_info" width="165">
							{$post['user_details']}
						</td>
					</tr>
				</table>
			</td>
		</tr>

		<tr>
			<td class="trow2 post_content {$unapproved_shade}">
				<span class="smalltext"><strong>{$post['icon']}{$post['subject']} {$post['subject_extra']}</strong></span>

				<div class="post_body" id="pid_{$post['pid']}">
					{$post['message']}
				</div>
				{$post['attachments']}
				{$post['signature']}

				<div class="post_meta" id="post_meta_{$post['pid']}">
				{$post['iplogged']}
				</div>
			</td>
		</tr>

		<tr>
			<td class="trow1 post_buttons {$unapproved_shade}">
				<div class="author_buttons float_left">
					{$post['button_email']}{$post['button_pm']}{$post['button_www']}{$post['button_find']}{$post['button_rep']}
				</div>
				<div class="post_management_buttons float_right">{$post['button_edit']}{$post['button_quickdelete']}{$post['button_quote']}{$post['button_multiquote']}{$post['button_report']}{$post['button_warn']}{$post['button_reply_pm']}{$post['button_replyall_pm']}{$post['button_forward_pm']}{$post['button_delete_pm']}
				</div>
			</td>
		</tr>
	</tbody>
</table>

And change the 4 in {$post['fid4']} to the ID of the custom profile field.
Thanks Mr Josh.

So my understanding is that for each username reference I want to change, I should replace the username with the custom-field in the corresponding template?

Thanks,

D
(2012-12-20, 03:22 PM)dham Wrote: [ -> ]Thanks Mr Josh.

So my understanding is that for each username reference I want to change, I should replace the username with the custom-field in the corresponding template?

Thanks,

D

Yup Smile

Here's Templates -> Member List -> memberlist_user

<tr>
	<td class="{$alt_bg}" align="center">{$user['avatar']}</td>
	<td class="{$alt_bg}">{$user['fid4']} ({$user['profilelink']})<br />
<span class="smalltext">
	{$user['usertitle']}<br />
	{$usergroup['groupimage']}
	{$user['userstars']}
</span></td>
	<td class="{$alt_bg}" align="center">{$user['regdate']}</td>
	<td class="{$alt_bg}" align="center">{$user['lastvisit']}</td>
	<td class="{$alt_bg}" align="center">{$user['postnum']}</td>
	{$referral_bit}
</tr>