Basically, create a functions_announce.php file with the following content:
Code: Select all
<?php
/**
*
* @package phpBB3
* @version $Id: functions_announce.php 0013 17:07 17/08/2008 kenny
* @copyright (c) 2005 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
/**
* Pull info for latest announcements // cherokee red - 08/13/2008
*
* $forum_id is the forum you want to pull info from
* $topic_limit is the amount of topics to display
* $title is the name you want to give to the block i.e. Announcements, or Latest Posts
*
*/
function get_announcements($forum_id, $topic_limit, $title)
{
global $db, $template;
global $phpbb_root_path, $phpEx;
$an_sql = 'SELECT topic_id, forum_id, topic_title
FROM ' . TOPICS_TABLE . '
WHERE forum_id = ' . $forum_id . '
ORDER BY topic_id DESC';
//query the db
$result = $db->sql_query_limit($an_sql, $topic_limit);
// Lets build a page ...
$template->assign_vars(array(
'U_FORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id),
'L_TITLE' => $title)
);
while ($announce = $db->sql_fetchrow($result))
{
$template->assign_block_vars('announce_row', array(
'TOPIC_TITLE' => $announce['topic_title'],
'U_ANNOUNCE' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $announce['forum_id'] . '&' . 't=' . $announce['topic_id']),
));
}
$db->sql_freeresult($result);
$template->set_filenames(array(
'content' => 'announce_body.html',
));
// Thanks Vic ^_^
$content = $template->assign_display('content', '', true);
return $content;
}
?>
Here is the HTML you'll need. Create a file called announce_body.html and place it in your templates folder with the following code.
Code: Select all
<div class="navbar">
<div class="inner"><span class="corners-top"><span></span></span>
<h3><a href="{U_FORUM}" title="{L_TITLE}">{L_TITLE}</a></h3>
<span style="font-size: 1.1em;">
<!-- BEGIN announce_row -->
<a href="{announce_row.U_ANNOUNCE}" title="{announce_row.POST_SUBJECT}" style="font-size: 1.1em;">{announce_row.TOPIC_TITLE}</a><br />
<!-- END announce_row -->
</span>
<span class="corners-bottom"><span></span></span></div>
</div>
<br />
Ok, now in the php file that will be serving the template, you need to include the function file.
So look at the top of the php file for the file includes and add a new one underneath
Code: Select all
include($phpbb_root_path . 'includes/functions_announce.' . $phpEx);
And look for where the file assigns variable to the template
Code: Select all
$template->assign_vars(array(
and in there add our function
Code: Select all
'ANNOUNCEMENT' => get_announcements('2', '5', 'Insert Block Title Here'),
The numbers in the brackets corresponds to our function file. The 1st number is the forum id we want to take the announcements from and the 2nd number is the amount of announcements. The last part is the title you want to show at the top of the block. It's seriously that simple.
Lastly, you need to edit the template file that corresponds to the php file you are using to show the announcements i.e. index_body.html for index.php, viewtopic_body.html for viewtopic.php
Simply add {ANNOUNCEMENT} wherever you want your announcement to show and you're set