MyBB Community Forums

Full Version: [Core edits] Forumdisplay Thread starter avatar + lastposter avatar
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey everyone. I just stumbled upon something pretty great and i thought i'd share it before it's lost.

Open forumdisplay.php and find:

$query = $db->query("
        SELECT t.*, {$ratingadd}t.username AS threadusername, u.username
        FROM ".TABLE_PREFIX."threads t
        LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid = t.uid)
        WHERE t.fid='$fid' $tuseronly $tvisibleonly $datecutsql2
        ORDER BY t.sticky DESC, {$t}{$sortfield} $sortordernow $sortfield2
        LIMIT $start, $perpage
    ");  

Replace it with this code:

$query = $db->query("
        SELECT t.*, {$ratingadd}t.username AS threadusername, u.username, u.avatar, lp.avatar AS lpavatar
        FROM ".TABLE_PREFIX."threads t
        LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid = t.uid)
        LEFT JOIN ".TABLE_PREFIX."users lp ON (lp.uid=t.lastposteruid) WHERE t.fid='$fid' $tuseronly $tvisibleonly $datecutsql2
        ORDER BY t.sticky DESC, {$t}{$sortfield} $sortordernow $sortfield2
        LIMIT $start, $perpage
    ");
  

Now in the same forumdisplay.php find:

$thread['pages'] = 0; 

Add this code above it:

//avatar
    if(!$thread['avatar']) {
    $thread_avatar = "<a href='member.php?action=profile&uid={$thread['uid']}'><img src='images/default_avatar.gif' alt='' title='{$thread['username']}' /></a>";
    }
    else
    {
    $thread_avatar = "<a href='member.php?action=profile&uid={$thread['uid']}'><img src='{$thread['avatar']}' alt='' title='{$thread['username']}' /></a>";
    }
    
    if(!$thread['lpavatar']) {
    $thread_lpavatar = "<a href='member.php?action=profile&uid={$thread['lastposteruid']}'><img src='images/default_avatar.gif' alt='' title='{$thread['lastposter']}' />";
    }
    else
    {
    $thread_lpavatar = "<a href='member.php?action=profile&uid={$thread['lastposteruid']}'><img src='{$thread['lpavatar']}' alt='' title='{$thread['lastposter']}' />";
    }
    //avatar end 

Open Forumdisplay_thread template replace:
<div>
	<span>{$prefix}{$gotounread}{$thread['threadprefix']}<a href="{$thread['threadlink']}" class="{$inline_edit_class} {$new_class}" id="tid_{$inline_edit_tid}">{$thread['subject']}</a>{$thread['multipage']}</span>
	<div class="author smalltext">{$thread['profilelink']}</div>
</div>

With this one:

		<div>
			<table>
				<tr>
					<div class="tvatar">{$thread_avatar}</div>
					<div class="tvatar2">{$thread_lpavatar}</div>
					<td>{$prefix}
						{$gotounread}
						{$thread['threadprefix']}
						<a href="{$thread['threadlink']}" class="{$inline_edit_class} {$new_class}" id="tid_{$inline_edit_tid}">{$thread['subject']}</a>
						{$thread['multipage']}<br> {$thread['profilelink']}
					</td>
				</tr>
			</table>
		</div>

Finally add this css style to your global.css:
#tvatar img {
background-color: rgb(252, 252, 255);
padding: 2px;
border: 1px solid #a5cae4;
border-radius: 4px; 
max-height: 36px;
max-width: 36px;
}

#tvatar2 img {
position: absolute;
display: block;
margin: 3px 0 0 -22px;
background-color: rgb(252, 252, 255);
border: 1px solid #a5cae4;
border-radius: 3px;
max-height: 20px;
max-width: 20px;
} 


[Image: eQSOvUo.png]

top picture shows the avatar of the last person who replied

bottom one is the thread starter. (i didn't apply css cuz i was too lazy)

The credits goes to the author: Marcus_Avrelius
Hi, thank you for your contribution Smile

As a suggestion, perhaps to use the core format_avatar() function to format the avatar.
https://github.com/mybb/mybb/blob/da7b32....php#L3218