MyBB Community Forums
Latest threads/posts from one category - Printable Version

+- MyBB Community Forums (https://community.mybb.com)
+-- Forum: 1.8 Support (https://community.mybb.com/forum-175.html)
+--- Forum: General Support (https://community.mybb.com/forum-176.html)
+--- Thread: Latest threads/posts from one category (/thread-210058.html)



Latest threads/posts from one category - DeepSea - 2017-04-27

Hello,
I dont know how could I change this mysql code to show latest threads/post from only one forum category.
For example  I have 5 category on my forum, but I want to show latest threads/post from one category.

Where should I add cat id in this query (portal.php)?
$query = $db->query("
		SELECT 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} AND t.visible='1' AND t.closed NOT LIKE 'moved|%'
		ORDER BY t.lastpost DESC
		LIMIT 0, ".$mybb->settings['portal_showdiscussionsnum']
	);

Thanks for help!


RE: Latest threads/posts from one category - MrBrechreiz - 2017-04-28

Try this

$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']
    );


1, 2, 3, 4 and 5 adapt to your forum ID's. (not forum cat)


RE: Latest threads/posts from one category - dragonexpert - 2017-04-28

If you use my Latest Threads On Index plugin, you can select which forums threads are pulled from, but it is only for index. It might work for the portal with a couple edits.


RE: Latest threads/posts from one category - DeepSea - 2017-04-28

(2017-04-28, 01:43 AM)MrBrechreiz Wrote: Try this

$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']
    );


1, 2, 3, 4 and 5 adapt to your forum ID's. (not forum cat)

Yeap, thanks its work as well!

Could you tell me how could I add thread "show" with only one prefix what i add in this forum?


RE: Latest threads/posts from one category - MrBrechreiz - 2017-04-28

I am not quite sure what you exactly, but try it with this variable

{$thread['threadprefix']}

in portal_latestthreads_thread Template and add this code on your portal.php

$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))
{


See screenshot


RE: Latest threads/posts from one category - DeepSea - 2017-05-01

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")."\";");
	}
}



RE: Latest threads/posts from one category - MrBrechreiz - 2017-05-01

look at here
https://community.mybb.com/thread-210088-post-1272470.html#pid1272470