Here's what i use and it works perfectly fine:
Note that this can be done w/o any session integration w/ phpbb3.
This code allows you to pull from ONE forum, or MULTIPLE forums, or ALL forums or exclude SOME forums.
If you want to parse HTML and/or Smilies paths simply change
echo (
with
echo str_ireplace("{smilies_path}","$urlPath/images/smilies/",htmlspecialchars_decode(
(and dont forget to close the ")" at the end either
)
This way, you can even parse smilies AND HTML if you decide to do so.
Also, this gives you the flexibility to have a hidden forum where you can quickly add/remove posts (for let's say a "news" section or a "downloads" section,) and link those entries to your main web site.
I dont have recent posts on my site right now, but you can check it out.
For a demo, you can look at the News and Announcements on the main page, and at the "Files" section. All those pages have data pulled from a hidden section in the forums. It's like having a CMS in the forum!
And if you need some help to even pull the download link to there, for the posts that have attachments, i can help with that too
(see the files section of my site).
http://www.frozenphoenix.org
Code: Select all
<!-- START - Latest topic repeat -->
<?php
// Number of latest topics you want shown.
$topicnumber = 10;
// Change this to your phpBB path relative to your document.
$urlPath = "/forum";
// Database Configuration (Where your phpBB config.php file is located)
include 'forum/config.php';
// begin variable statements.
$table_topics = $table_prefix. "topics";
$table_forums = $table_prefix. "forums";
$table_posts = $table_prefix. "posts";
$table_users = $table_prefix. "users";
$link = mysql_connect("$dbhost", "$dbuser", "$dbpasswd") or die("Could not connect");
mysql_select_db("$dbname") or die("Could not select database");
// in my case, forum number 2 5 9 10 11 17 21 22 23 24 25 26 27 28 29 are public forums where the data i pull can be seen by anyone. Read below if you want to know how to EXCLUDE a forum instead of reading from all public forums.
$query = "SELECT t.topic_id, t.topic_title, t.topic_last_post_id, t.forum_id, p.post_id, p.poster_id, p.post_time, u.user_id, u.username
FROM $table_topics t, $table_forums f, $table_posts p, $table_users u
WHERE t.topic_id = p.topic_id AND
f.forum_id = t.forum_id AND
(t.forum_id = 2 || t.forum_id = 5 || t.forum_id = 9 || t.forum_id = 10 || t.forum_id = 11 || t.forum_id = 17 || t.forum_id = 21 || t.forum_id = 22 || t.forum_id = 23 || t.forum_id = 23 || t.forum_id = 25 || t.forum_id = 26 || t.forum_id = 27 || t.forum_id = 28 || t.forum_id = 29) AND
t.topic_status <> 2 AND
p.post_id = t.topic_last_post_id AND
p.poster_id = u.user_id
ORDER BY p.post_id DESC LIMIT $topicnumber";
$result = mysql_query($query) or die("Query failed");
//note here that (t.forum_id = 2 || t.forum_id = 5 || t.forum_id = 9 || t.forum_id = 10 || t.forum_id = 11 || t.forum_id = 17 || t.forum_id = 21 || t.forum_id = 22 || t.forum_id = 23 || t.forum_id = 23 || t.forum_id = 25 || t.forum_id = 26 || t.forum_id = 27 || t.forum_id = 28 || t.forum_id = 29)
//are the forums that have public access to them. I ONLY want the data pulled from these forums.
//Also, this can be done if you want to use ALL forums except one lets say, like this:
//t.forum_id != 2 (this means it will NOT pull from forum 2)
//begin display
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo htmlspecialchars_decode("<table width='100%' border='0' cellspacing='0' cellpadding='0'><tr><td colspan='2' align='left'><span class='style2'><a href=\"$urlPath/viewtopic.php?f=$row[forum_id]&t=$row[topic_id]&p=$row[post_id]#p$row[post_id]\">" .
$row["topic_title"] .
"</a></span></td></tr><tr><td align='left'><div align='left' class='style5'>By <a href=\"$urlPath/memberlist.php?mode=viewprofile&u=$row[user_id]\">" .
$row["username"] . "</a></div></td><td align='right'><div align='right' class='style5'>" . date('m.d.y', $row["post_time"]) . "</div></td></tr></table><hr>");
}
mysql_free_result($result);
mysql_close($link);
?>
<!-- End Latest topic repeat -->
I'm planning on adding a "previous/next" button in the near future for the news/files/links section. (i.e. if theres over $topicnumber number of news, display the next $topicnumber posts from that section.)
Don't forget to change the echo string accordingly. Feel free to PM me if you got any questions.
Hope this helps a few people.