MyBB Community Forums

Full Version: Username style not showing on latest thread on sidebar
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am using the manual way of showing latest thread on sidebar using modification on index.php
But it is not showing username colors, can you please help me add it ?
$unviewable = get_unviewable_forums(true);
if($unviewable)
{
        $unviewwhere = " AND fid NOT IN ($unviewable)";
}

        $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, 20"
        );
        while($thread = $db->fetch_array($query))
        {
                $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")."\";");
        } 
(2016-05-28, 11:48 AM)Puzzlemaster Wrote: [ -> ]I am using the manual way of showing latest thread on sidebar using modification on index.php
But it is not showing username colors, can you please help me add it ?
$unviewable = get_unviewable_forums(true);
if($unviewable)
{
        $unviewwhere = " AND fid NOT IN ($unviewable)";
}

        $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, 20"
        );
        while($thread = $db->fetch_array($query))
        {
                $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")."\";");
        } 

SELECT t.*, u.username

to

SELECT t.*, u.username, u.displaygroup, u.usergroup


and this:
$lastposterlink = build_profile_link($thread['lastposter'], $thread['lastposteruid']);

with:
$lastposterlink = build_profile_link(format_name($thread['lastposter'], (!empty($thread['displaygroup']) ? $thread['displaygroup'] : $thread['usergroup'])), $thread['lastposteruid']);


Should work.
(2016-05-28, 10:16 PM)Sazze Wrote: [ -> ]
(2016-05-28, 11:48 AM)Puzzlemaster Wrote: [ -> ]I am using the manual way of showing latest thread on sidebar using modification on index.php
But it is not showing username colors, can you please help me add it ?
$unviewable = get_unviewable_forums(true);
if($unviewable)
{
        $unviewwhere = " AND fid NOT IN ($unviewable)";
}

        $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, 20"
        );
        while($thread = $db->fetch_array($query))
        {
                $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")."\";");
        } 

SELECT t.*, u.username

to

SELECT t.*, u.username, u.displaygroup, u.usergroup


and this:
$lastposterlink = build_profile_link($thread['lastposter'], $thread['lastposteruid']);

with:
$lastposterlink = build_profile_link(format_name($thread['lastposter'], (!empty($thread['displaygroup']) ? $thread['displaygroup'] : $thread['usergroup'])), $thread['lastposteruid']);


Should work.

It is showing different colors for different users.
Something went wrong there i guess.