Topic: Script to get news/blog entries from the topics in a specified forum
Punbb News Script - by Jesse Spillane (http://www.jessespillane.com)
edits:
March 8th Fixed the comment link. Sorry if this caused any trouble.
March 13th Now shows poster name below post title.
Motivation
My motivation was to create a news or blog system which takes the the latest topics in a specified forum and uses them as news entries on my site. For example, I have a forum which the permissions are set so only administrators can post topics. Each of these topics are treated as news entries. I wanted my index page to display the latest X posts in the news forum. I didn't want to use the admin news generator plugin as I wanted this system to be dynamic. I also didn't want to sort through bloated portal system mods and rip them apart to get a few features I wanted.
I searched for about an hour for a script which did this, but I eventually gave up and decided to write one myself. I figure someone may get some use out of it.
Instructions
The script is very simple to use. This file will output the html for the news. Below is a description of the variables which you should set:
$news_forum_id - Set this to the forum which contains your news
$limit - This is the number news entries to display
$forum_path - Set this to the path of your punbb install.
<?php
/**
Punbb News Script
Written by: Jesse Spillane (http://www.jessespillane.com)
*/
$news_forum_id = 5;
$limit = 5;
$forum_path = './forum/';
define('PUN_ROOT', $forum_path);
require PUN_ROOT.'include/common.php';
define('PUN_TURN_OFF_MAINT', 1);
define('PUN_QUIET_VISIT', 1);
require PUN_ROOT.'include/parser.php';
echo "<h2>News</h2>";
$result = $db->query('select id, subject, num_replies, posted from '.$db->prefix.'topics WHERE forum_id='.$news_forum_id.' ORDER BY -posted LIMIT '.$limit.';')or error('Unable to fetch topic list', __FILE__, __LINE__, $db->error());
while ($row = $db->fetch_assoc($result))
{
$id = $row['id'];
$subject = $row['subject'];
$num_replies = $row['num_replies'];
$posted = date("F j, Y, g:i a", $row['posted']);
$result2 = $db->query('select message, poster from '.$db->prefix.'posts WHERE topic_id='.$id.' ORDER BY id LIMIT 1 ')or error('Unable to fetch topic list', __FILE__, __LINE__, $db->error());
$post = $db->fetch_assoc($result2);
$message = parse_message($post['message'], 1);
$poster = $post['poster'];
?>
<div style='margin-bottom: 30px;'>
<h3>
<?php echo $subject; ?>
</h3>
<hr />
<div>
<i> by <?php echo $poster; ?> </i>
</div>
<div>
<i> <?php echo $posted; ?> </i>
</div>
<div>
<?php echo $message; ?>
</div>
<div style='float: right;'>
<?php
echo '<a href='.$forum_path.'viewtopic.php?id='.$id.'>Comments ('.$num_replies.')</a>';
?>
</div>
</div>
<br />
<?php
}
?>
Sorry if this has been done. It is quite simple.