MyBB Community Forums

Full Version: Latest Threads on Portal Show Thread Poster
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey,

I'm trying to modify MyBB core files so that in the Latest Threads box on the portal I can show the Thread Creator. By default it shows this:

Quote:ThreadName (with link)
Last Post: LastPosterName (with link)
Time/Date
» Replies: #
» Views: #

I want to have Thread Name (with link) by Thread Author (with link).

This is the relevant PHP from portal.php.

// Latest forum discussions
if($mybb->settings['portal_showdiscussions'] != 0 && $mybb->settings['portal_showdiscussionsnum'])
{
	$altbg = alt_trow();
	$threadlist = '';
	$query = $db->query("
		SELECT t.*, u.username
		FROM ".TABLE_PREFIX."threads t
		LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=t.uid)
		WHERE 1=1 $unviewwhere AND t.visible='1' AND t.closed NOT LIKE 'moved|%'
		ORDER BY t.lastpost DESC 
		LIMIT 0, ".$mybb->settings['portal_showdiscussionsnum']
	);
	while($thread = $db->fetch_array($query))
	{
		$forumpermissions[$thread['fid']] = forum_permissions($thread['fid']);

		// Make sure we can view this thread
		if($forumpermissions[$thread['fid']]['canview'] == 0 || $forumpermissions[$thread['fid']]['canviewthreads'] == 0 || $forumpermissions[$thread['fid']]['canonlyviewownthreads'] == 1 && $thread['uid'] != $mybb->user['uid'])
		{
			continue;
		}
		
		$lastpostdate = my_date($mybb->settings['dateformat'], $thread['lastpost']);
		$lastposttime = my_date($mybb->settings['timeformat'], $thread['lastpost']);
		// Don't link to guest's profiles (they have no profile).
		if($thread['lastposteruid'] == 0)
		{
			$lastposterlink = $thread['lastposter'];
		}
		else
		{
			$lastposterlink = build_profile_link($thread['lastposter'], $thread['lastposteruid']);
		}
		if(my_strlen($thread['subject']) > 25)
		{
			$thread['subject'] = my_substr($thread['subject'], 0, 25) . "...";
		}
		$thread['subject'] = htmlspecialchars_uni($parser->parse_badwords($thread['subject']));
		$thread['threadlink'] = get_thread_link($thread['tid']);
		$thread['lastpostlink'] = get_thread_link($thread['tid'], 0, "lastpost");
		eval("\$threadlist .= \"".$templates->get("portal_latestthreads_thread")."\";");
		$altbg = alt_trow();
	}
	if($threadlist)
	{ 
		// Show the table only if there are threads
		eval("\$latestthreads = \"".$templates->get("portal_latestthreads")."\";");
	}
}

I believe I need to use $thread['username'] but how do I fetch the username and output it in the templates?

Thanks,
Jack
The username is already available to you (as is everything else in the threads table). You can use {$thread['username']} directly in the template. To build up the link to the author's profile you can pick up the uid and hardcode it like so:

<a href="{$mybb->settings['bburl']}/member.php?uid={$thread['uid']}">{$thread['username']}</a>

Or something like this if you're using Google SEO:

<a href="{$mybb->settings['bburl']}/User-{$thread['username']}">{$thread['username']}</a>

But of course this is cheating. The proper way to do it is to add this line just before the eval() function:

$authorlink = build_profile_link($thread['username'], $thread['uid']);

And then use the following in the portal_latestthreads_thread template:

by {$authorlink}
After this:
$thread['subject'] = htmlspecialchars_uni($parser->parse_badwords($thread['subject']));/php]

Add after:
[php]$thread['username'] = build_profile_link($thread['username'], $thread['uid']);

Now add {$thread['username']} in your "portal_latestthreads_thread" template.

Fábio at the rescue! Toungue

Anyways, if you opt out for the core edit, for something like this I would recommend you the Patches Plugin.