MyBB Community Forums

Full Version: Using code from the Portal on forum index
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Basically, I would like to use the following two bits of code on my forum index;

{$announcement['subject']}
{$post['attachments']}

These are used and only work in the portal's templates, but I would like to get it to work in my forum index template to display some recent attachments. What do I have to add (I'm guessing to index.php) to get it to work?

Thanks Smile

EDIT: Nevermind, I managed to do it, just need to edit the display a little bit Smile
To get the last announcement you would need to query for it, here is some code taken from the portal file:
// Get forums user cannot view
$unviewable = get_unviewable_forums(true);
if($unviewable)
{
	$unviewable = " AND fid NOT IN ({$unviewable})";
}

// Validate announcement fids
$announcementsfids = implode(',', array_map('intval', explode(',', $mybb->settings['portal_announcementsfid'])));
if($announcementsfids)
{
	if(($numannouncements = intval($mybb->settings['portal_numannouncements'])) < 1)
	{
		$numannouncements = 10;
	}

	$query = $db->simple_select('threads', '*', "fid IN ({$announcementsfids}) AND visible='1' AND closed NOT LIKE 'moved|%'{$unviewable}", array('order_by' => 'dateline', 'order_dir' => 'desc', 'limit' => $numannouncements));
	$announcement = $db->fetch_array($query);
}

For attachments it would be similar; you need to query the latest visible attachments from forums where the user can actually read threads in, threads/posts that are marked as visible (unless you are a mod, something I didn't include in the piece of code above), etc.
Thanks, I managed to get it working Smile

I don't suppose you would know what part of portal.php I would need to edit to make it so that it only fetches threads that have attachments?

At the moment I'm using this in my template;

<if $post['thumblist'] then>
<a href="{$mybb->settings['bburl']}/{$announcement['threadlink']}" title="{$announcement['subject']}">{$post['attachments']}</a>
</if>

But ideally would rather have it so that it decides that at the php side.

EDIT: I think I've done it.

I changed this line;

WHERE t.fid IN (".$announcementsfids.") AND t.tid IN (0{$tids}) AND t.visible='1' AND t.closed NOT LIKE 'moved|%'

to this;

WHERE t.fid IN (".$announcementsfids.") AND t.tid IN (0{$tids}) AND t.visible='1' AND t.closed NOT LIKE 'moved|%' AND t.attachmentcount > 0  

and it seems to be working Big Grin
(2012-08-28, 06:11 AM)Omar G. Wrote: [ -> ]To get the last announcement you would need to query for it, here is some code taken from the portal file:
// Get forums user cannot view
$unviewable = get_unviewable_forums(true);
if($unviewable)
{
	$unviewable = " AND fid NOT IN ({$unviewable})";
}

// Validate announcement fids
$announcementsfids = implode(',', array_map('intval', explode(',', $mybb->settings['portal_announcementsfid'])));
if($announcementsfids)
{
	if(($numannouncements = intval($mybb->settings['portal_numannouncements'])) < 1)
	{
		$numannouncements = 10;
	}

	$query = $db->simple_select('threads', '*', "fid IN ({$announcementsfids}) AND visible='1' AND closed NOT LIKE 'moved|%'{$unviewable}", array('order_by' => 'dateline', 'order_dir' => 'desc', 'limit' => $numannouncements));
	$announcement = $db->fetch_array($query);
}

For attachments it would be similar; you need to query the latest visible attachments from forums where the user can actually read threads in, threads/posts that are marked as visible (unless you are a mod, something I didn't include in the piece of code above), etc.

Will that code work without using php in templates or template conditionals?
No, it will not. I doubt it work (as is) even if you use the PHP In Templates plugin, TBH I'm unsure it will work even if you paste it in the global.php file, the code may be incomplete.