MyBB Hacks

Full Version: How to display forum names on portal page
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I personally find it a nice thing to have (I have this at Endless Paradigm)

To add the forum name, for each portal announcement, just perform the following code edits.

Open up portal.php.
Find:

PHP Code:
$query = $db->query("
	SELECT t.*, t.username AS threadusername, u.username, u.avatar
	FROM ".TABLE_PREFIX."threads t
	LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid = t.uid)
	WHERE fid IN (".$mybb->settings['portal_announcementsfid'].") AND t.visible='1' AND t.closed NOT LIKE 'moved|%'
	ORDER BY t.dateline DESC
	LIMIT 0, ".$mybb->settings['portal_numannouncements']
);


Replace with:

PHP Code:
$query = $db->query("
	SELECT t.*, t.username AS threadusername, u.username, u.avatar, f.name AS forumname
	FROM ".TABLE_PREFIX."threads t
	LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid = t.uid)
	LEFT JOIN ".TABLE_PREFIX."forums f ON (f.fid = t.fid)
	WHERE t.fid IN (".$mybb->settings['portal_announcementsfid'].") AND t.visible='1' AND t.closed NOT LIKE 'moved|%'
	ORDER BY t.dateline DESC
	LIMIT 0, ".$mybb->settings['portal_numannouncements']
);


Next, open up your portal_announcement template, and place {$announcement['forumname']} wherever you want it to appear.  You can use {$announcement['fid']} if you need to grab the FID of the forum.

That's it!

Thx for sharing !
Thank you but if I want to show it in front of each thread subject in "Lastest Threads" section not in announcement section.

ex.
[Tutorials, Guides, Mods & Resources] How to display forum names on portal page
[Releases] AJAX Quick Reply 1.2

How to midify code?
Thank you again
Oh okay, sorry.

In portal.php
Find:

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

Replace with:

PHP Code:
	$uv = str_replace('fid', 't.fid', $unviewwhere);
	$query = $db->query("
		SELECT t.*, u.username, f.name AS forumname
		FROM ".TABLE_PREFIX."threads t
		LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=t.uid)
		LEFT JOIN ".TABLE_PREFIX."forums f ON (f.fid=t.fid)
		WHERE 1=1 $uv AND t.visible='1' AND t.closed NOT LIKE 'moved|%'
		ORDER BY t.lastpost DESC 
		LIMIT 0, ".$mybb->settings['portal_showdiscussionsnum']
	);

Then edit your portal_latestthreads_thread template - add {$thread['forumname']} wherever you want the name to appear.  You can also use {$thread['fid']} if you need the FID.

Nice.

I've been looking for something like this, and it comes in handy if you're pulling posts from multiple sections as users know where it's coming from.
as useal u read my mind Tongue
I was looking for it too, thanks mate for sharing it..
ُEdit: the {$announcement['forumname']} not working, I tryed to add

PHP Code:
<a href="{$mybb->settings['bburl']}/forum-{$announcement['fid']}.html">{$announcement['forumname']}</a>

the forum fid working good whene I view the page source, but there is no input replaced with {$announcement['forumname']}

Note: I applyed the changes in this topic http://mybbhacks.zingaburga.com/showthread.php?tid=54

Thank you very much. It's work! Tongue
pepotiger Wrote:as useal u read my mind Tongue
I was looking for it too, thanks mate for sharing it..
ُEdit: the {$announcement['forumname']} not working, I tryed to add

PHP Code:
<a href="{$mybb->settings['bburl']}/forum-{$announcement['fid']}.html">{$announcement['forumname']}</a>

the forum fid working good whene I view the page source, but there is no input replaced with {$announcement['forumname']}

Note: I applyed the changes in this topic http://mybbhacks.zingaburga.com/showthread.php?tid=54

Oh yes, there will be a conflict if you copy the code exactly...
If you're using pagination on portal as well, instead of using the replacement in the first post, use this replacement:

PHP Code:
$query = $db->query("
	SELECT t.*, t.username AS threadusername, u.username, u.avatar, f.name AS forumname
	FROM ".TABLE_PREFIX."threads t
	LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid = t.uid)
	LEFT JOIN ".TABLE_PREFIX."forums f ON (f.fid = t.fid)
	WHERE t.fid IN (".$mybb->settings['portal_announcementsfid'].") AND t.visible='1' AND t.closed NOT LIKE 'moved|%'
	ORDER BY t.dateline DESC
	LIMIT ".(($page-1)*$perpage).", ".$perpage
);

working very well now.. thanks mate Smile
work for me also  Smile
Reference URL's