This is a php code it show the latest forum post with phpBB3 on the homepage of your website. It work with your config.php in your PHPBB directory. If you wish to show more then the latest 5 posts you can change the $topicnumber to whatever you wish to display.
<?php
// How Many Topics you want to display?
$topicnumber = 5;
// Change this to your phpBB path
$urlPath = "/phpbb";
// Database Configuration (Where your phpBB config.php file is located)
include 'phpbb/config.php';
$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");
$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 != 4 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");
print "<table cellpadding='3' cellSpacing='2' width='640'>";
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "<tr valign='top'><td><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"1\"><font color=\"#FFCC00\"><b><a href=\"$urlPath/viewtopic.php?f=$row[forum_id]&t=$row[topic_id]&p=$row[post_id]#p$row[post_id]\" TARGET=\"_blank\">" .
$row["topic_title"] .
"</a></td></font></b><td><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"1\"><font color=\"#C0C0C0\"> by: <a href=\"$urlPath/memberlist.php?mode=viewprofile&u=$row[user_id]\" TARGET=\"_blank\">" .
$row["username"] .
"</td><td><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"1\"><font color=\"#C0C0C0\">" .
date('F j, Y, g:i a', $row["post_time"]) .
"</td></tr></font>";
}
print "</table>";
mysql_free_result($result);
mysql_close($link);
?>
Thanks for the code, which works perfectly with phpbb3, but I have an issue to display the German umlaut in my website.
If applying the code I just see a � instead of the umlaut Ä, Ü or Ö.
Can sombody support what I have to put in the code to have displayed the umlaut correctly? (both database and website are in UTF-8)
Thanks in advance.
All I can get to display is Could Not Connect. From what I can tell that's displayed if login fails? I am still trying to re-teach myself some of this stuff after a lengthy break in web dev. My URL path I put in the URL not referencing the folder relative to where the file is. Am I supposed to put my login and password in the code or let it call it from the config.php file?
Any help would be appreciated.
This is awesome! However, what I would love is the ability to also add an "excerpt" from the latest post, rather than just the post title/link.
For example:
Post Title (linked)
Post Excerpt (140 characters) (more link...)
Posted by (user) on (date)
Can anyone help with this? I don't know how to select the actual post content from the db OR how to only show the first 140 characters...
Thanks!
Hi,
This is an excellent thread, easy for a novice like me to understand. Thanks to all.
Can someone post an example of latestpost.asp with only the topic appearing. I am using a right side block on my home page and it is limited in size.
Also, can you include code that when the visitor clicks a topic, and they are not registered, present the Register page otherwise present the Login page.
Thank you very much in advance.
can anyone help me with these questions please ?
I have a BB that will eventually have many Categories & Forums - is there a way to automatically include forums into the latest post snippet without having to add each forum or forum number into the code?
also is there a way I can remove the username & date from the snippet - so just the post's topic appears
my original config.php states:
<?php
// phpBB 3.0.x auto-generated configuration file
// Do not change anything in this file!
$dbms = 'mysqli';
$dbhost = 'localhost';
$dbport = '';
$dbname = 'fatewhee_BBS';
$dbuser = 'fatewhee_WarrenR';
$dbpasswd = 'Haonan_6996';
$tableprefix = 'phpbb';
$acm_type = 'file';
$load_extensions = '';
@define('PHPBB_INSTALLED', true);
// @define('DEBUG', true);
// @define('DEBUG_EXTRA', true);
?>
where should i insert the code in this original code?
and also, how can i make it display on my home page (in a content box that i create), since i've only changed the config.php for the forum, i think i'd need an additional step to call it up in my homepage?
Sorry, really dump about programming and coding etc.
this works well & is really easy to use - but I have 2 questions
I have a BB that will eventually have many Categories & Forums - is there a way to automatically include forums into the latest post snippet without having to add each form or forum number into the code?
also is there a way I can remove the username & date from the snippet - so just the post's topic appears
Never mind, figured it out. For anyone else wanting to do this, change the query to something like this:
$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 <> X AND
t.topic_status <> 2 AND
p.post_id = t.topic_last_post_id AND
p.poster_id = u.user_id AND
ORDER BY p.post_id DESC LIMIT $topicnumber";
Note the line "t.forum_id <> X AND". Change X to the number of the forum. This number can be found by looking at the URL of the forum. It is f=X in the URL. For example http://www.yourwebsite.com/viewforum.php?f=5. In this case it is 5. You can repeat the line t.forum_id <> X AND for each for you want excluded.
Nice!
Just one little thing: the script does not produce valid html (any version)
The font and bold tags get opened inside the
, but closed outside it (). It's no biggie since anyone that cares probably knows how to fix it, but still I wanted to bring it up. Also you could add some line breaks there for improved readability.But yeah anyway, thanks a bunch, the snippet was a great help to me. :)
Heya Furb, good to see you pop in.