Jump to the post that solved this thread.
Solved: 2 Years, 5 Months, 1 Week ago Latest threads/posts sort by prefix
#1
Solved: 2 Years, 5 Months, 1 Week ago
Hello,
I use this code to show latest threads/posts (from portal.php).
$read_from_forum = " AND t.fid IN ('1','2','3','4','5')";
    $query = $db->query("
        SELECT t.*, t.tid, t.fid, t.uid, t.lastpost, t.lastposteruid, t.lastposter, t.subject, t.replies, t.views, u.username
        FROM ".TABLE_PREFIX."threads t
        LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=t.uid)
        WHERE 1=1 {$excludeforums}{$tunviewwhere}{$read_from_forum} AND t.visible='1' AND t.closed NOT LIKE 'moved|%'
        ORDER BY t.lastpost DESC
        LIMIT 0, ".$mybb->settings['portal_showdiscussionsnum']
    ); 
https://community.mybb.com/thread-210058.html

How could I add one more query to sort by prefix too?
Where can I get a "matching" variable for it?

Thanks for help!
Reply
#2
Solved: 2 Years, 5 Months, 1 Week ago
Do you mean show threads with one or more specific prefix that you specific?
Reply
#3
Solved: 2 Years, 5 Months, 1 Week ago
One or more (It all depends - sometimes 2 or more)
Reply
#4
Solved: 2 Years, 5 Months, 1 Week ago
Add this

$thread['threadprefix'] = $threadprefix = '';
		if($thread['prefix'] != 0)
		{
			$threadprefix = build_prefixes($thread['prefix']);
			if(!empty($threadprefix))
			{
				$thread['threadprefix'] = $threadprefix['displaystyle'].' ';
			}
		}

after

while($thread = $db->fetch_array($query))
	{

Use this variable

{$thread['threadprefix']}

in the portal template portal_latestthreads_thread before

<strong><a href="{$mybb->settings['bburl']}/{$thread['threadlink']}">{$thread['subject']}</a></strong>

Is that what you meant?
Reply
#5
Solved: 2 Years, 5 Months, 1 Week ago
(2017-04-29, 04:47 PM)MrBrechreiz Wrote: Add this

$thread['threadprefix'] = $threadprefix = '';
		if($thread['prefix'] != 0)
		{
			$threadprefix = build_prefixes($thread['prefix']);
			if(!empty($threadprefix))
			{
				$thread['threadprefix'] = $threadprefix['displaystyle'].'&nbsp;';
			}
		}

after

while($thread = $db->fetch_array($query))
	{

Use this variable

{$thread['threadprefix']}

in the portal template portal_latestthreads_thread before

<strong><a href="{$mybb->settings['bburl']}/{$thread['threadlink']}">{$thread['subject']}</a></strong>

Is that what you meant?

It doesn't work for me - when i add this {$thread['threadprefix']} then nothing displays ;/

Thats my portal_latestthreads_thread with added {$thread['threadprefix']}:

<tr>
<td class="{$altbg}">
{$thread['threadprefix']}
<strong><a href="{$mybb->settings['bburl']}/{$thread['threadlink']}">{$thread['subject']}</a></strong>
<span class="smalltext"><br />
{$lang->forum} <a href="{$thread['forumlink']}">{$thread['forumname']}</a><br />
<a href="{$thread['lastpostlink']}">{$lang->latest_threads_lastpost}</a> {$lastposterlink}<br />
{$lastpostdate}<br />
<strong>&raquo; </strong>{$lang->latest_threads_replies} {$thread['replies']}<br />
<strong>&raquo; </strong>{$lang->latest_threads_views} {$thread['views']}
</span>
</td>
</tr>

and my portal.php

while($thread = $db->fetch_array($query))
	{
        $thread['threadprefix'] = $threadprefix = '';
        if($thread['prefix'] != 0)
        {
            $threadprefix = build_prefixes($thread['prefix']);
            if(!empty($threadprefix))
            {
                $thread['threadprefix'] = $threadprefix['displaystyle'].'&nbsp;';
            }
        }
		$forumpermissions[$thread['fid']] = forum_permissions($thread['fid']);

		// Make sure we can view this thread
		if(isset($forumpermissions[$thread['fid']]['canonlyviewownthreads']) && $forumpermissions[$thread['fid']]['canonlyviewownthreads'] == 1 && $thread['uid'] != $mybb->user['uid'])
		{
			continue;
		}

		$lastpostdate = my_date('relative', $thread['lastpost']);
		$lastposter = htmlspecialchars_uni($thread['lastposter']);
		$thread['replies'] = my_number_format($thread['replies']);
		$thread['views'] = my_number_format($thread['views']);

		// Don't link to guest's profiles (they have no profile).
		if($thread['lastposteruid'] == 0)
		{
			$lastposterlink = $lastposter;
		}
		else
		{
			$lastposterlink = build_profile_link($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");
		$thread['forumlink'] = get_forum_link($thread['fid']);
		$thread['forumname'] = $forum_cache[$thread['fid']]['name'];
		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")."\";");
	}
}
Reply
#6
Solved: 2 Years, 5 Months, 1 Week ago
Here is my portal.php


Attached Files
.php   portal.php (Size: 22.02 KB / Downloads: 48)
Reply
#7
Solved: 2 Years, 5 Months, 1 Week ago
Yeap, its work as well, thanks!
Reply
#8
Solved: 2 Years, 5 Months, 1 Week ago
Gooood, thx ^^
Reply
Jump to the post that solved this thread.


Forum Jump:


Users browsing this thread: 1 Guest(s)