Latest posts standalone script for phpbb3 and phpbb2

I have tested this script on phpbb2 and phpbb3 and it works like a charm. If you have one, make sure you exclude your private section (for example t.forum_id != 4, where 4 is your private forum’s number). You can include this in your blog’s sidebar, a portal or a website. You can apply different filters by playing with the WHERE condition. Basically this script generates a table which is populated from the phpbb’s database according to the conditions which are imposed.

Of course you can customize it’s output by modifying the $query variable. If you are a newbie and need a quick php Where clause reference as you want to get a hang of the operators, check this one out: PHP MySQL Where Clause

Finally here’s the script:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
 <?php
    // How Many Topics you want to display?
    $topicnumber = 5;
    // Scrolling towards up or down?
    $scroll = "up";
    // Change this to your phpBB path
    $urlPath = "/forum";
 
    // Database Configuration (Where your phpBB config.php file is located)
    include 'forum/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 "<marquee id=\"recent_topics\" behavior=\"scroll\" direction=\"$scroll\" height=\"170\" scrolldelay=\"100\" scrollamount=\"2\" onMouseOver=\"document.all.recent_topics.stop()\" onMouseOut=\"document.all.recent_topics.start()\">
    <table cellpadding='3' cellSpacing='2' width='350'>";
    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></marquee>";
    mysql_free_result($result);
    mysql_close($link);
    ?>

Feel free to use it as you want. If you have any questions just drop a comment.

Social bookmarking:
  • Digg
  • del.icio.us
  • Google Bookmarks
  • StumbleUpon
  • Technorati
  • Mixx
  • Sphinn
  • Reddit
  • Live
  • Twitter
  • Yahoo! Bookmarks

This entry was posted in php, phpbb3, scripts and tagged , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.
  • X420
    Hey alle,
    i have a phpb3 forum. http://Solormen.dk. In my header i have put a facebook pluging. I want to show recent6 topic left to it...in wich file i put this script?

    I have put the facebook plugin in overalle_header.html
  • Lennart Bykov
    Horrible HTML code.. throw FP in the garbage ! Use CSS !
    nice PHP..
    thanks & cheers !
  • Hi there, first of all, thank you for this great script, works excellent at phpBB 3.0.7.

    I have two questions:

    1) is there any way to modify the script, so the users could see only topics, which they have permissions to? e.g. normal user sees only public forums, and moderators sees public and private forums?

    2) I have my phpBB forum devided into 8 "categories" (4 private+4 public) which has own forum ID, but when I use this ID, it doesn't working and I need to use ID of the specific forum to exclude them. FYI forum "categories" include 4 IDs and specific forum IDs include 14 IDs, so the difference is quite big...

    Any ideas?

    Thanks a lot
  • edwindeprez
    Hi,
    your script works indeed like a charm also on the latest phpBB 3.0.7 -PL1, thanks.
    This is maybe newbie question, because my php knowledge is subzero, but I need some help here.
    I cut the script above and wanted to implement it in my own home page (external page) but it completely broke the layout and wouldn't work.
    It does work however when no other html code is added to the page.
    But how do you implement such a script into another page? Which is probably what most users would like to do...
    Any help is welkom.

    Kind regards.
    Edwin
  • Thanx very much :)

    Note, if you want to select time in correct format and guest usernames as well you could use:

    SELECT ...
    DATE_FORMAT(ADDDATE('1970-01-01', ROUND(p.post_time/86400)), '%d.%m.%Y') AS post_time,
    IF(p.post_username = '', u.username, p.post_username) AS username
  • Andrew
    Hi. This is a great script. I've used it to put a latest post box to the right of one of my forums as a PHP include in the template. Works brilliantly.

    Just one question. How would I change the script so instead of outputting the topic title, outputting the title of the latest post?

    I understand (or imagine at least) I'll need to change the database query somehow, then change the "topic_title" in the output later to the post title as well as the link, but don't know what I'd need to query for, etc.

    I.e. I can work out what I need to do, but don't know how to actually do it, so any help would be greatly appreciated.

    All the best.
  • There are some problems on mouse over. These appared after upgraded to phpbb version 3.0.6
  • it doesnt work for me? i made a html page and paste this code you guys gave me and it shows all the codes....can you guys take a look at it....which part should i replace...
    here is my phpbb2 websites http://anhsaobang.myfreeforum.org/
  • skidplate
    I am trying to change the font face and color, but it isn't changing (all i am seeing is ugly blue underlined text). Also, me not being very familiar with php... how do I change what is displayed? Are there any instructions for this??
  • bozz282
    Hi,

    Great script. I have two issues which I can't seem to resolve. The first is that when I click on a recent forum topic, a new window opens (which is fine) but, the url is wrong because the script adds quotations to the link. Example : url is http://www.mysite.com/"forum/viewtopic.php?f=5&... which results in an error page (page not found) but, if I remove the quotes : http://www.mysite.com/forum/viewtopic.php?f=5&t... the page / link displays fine.

    Second problem is that the mouse over doesnt work ? i.e. the scroll continues to scroll and I cannot stop it

    Thanks for your time in developing this neat script !
  • dan_vaida
    And how exactly did you tackle the first issue ?
  • bozz282
    I trawled through the code until I discovered two "%22" within the echo link tag. %22 = " (quotation mark) which explains why there was a quotation mark added into my url.

    I assumed that Microsoft Front Page interpreted the quotation mark badly and inserted the %22 instead?

    At first I changed the %22 into " but that made the code fail. So, I removed the %22 and it worked.
  • dan_vaida
    I am really glad that you managed to figure it out by yourself. that's what this is all about in the end. cheers
  • bozz282
    Still no luck with the mouseover though. I have eliminated Front Page as the cause because I replaced the code using notepad as my editor.

    Could it be that the mouseover won't work because it's nested inside a CSS Div ?
  • bozz282
    OK, I found the quotation marks in the url problem. It seems that Microsoft Front Page inserted some %22 into the code which then showed up in the url's.

    Still working on the onMouseOver issue which I suspect is to do with Front Page again
  • poxy
    how i can change language to "UTF-8"
  • poxy
    how i can change language to "UTF-8"
  • Got to say this is awesome script!
    Easy as A B C and works like a charm with phpBB(3.0.5). Thank you DAN!

    Put it to action here:
    Best Youtube Videos, Greatest Clips
  • Hi I'm trying to use your script, but it produce ????? (question marks) for Cyrillic language.

    DB is in UTF and it shouldn't be a problem. The forum works great in Cyrillic, but this external function produce ?????

    Any ideas?
  • MichaellaS
    tks for the effort you put in here I appreciate it!
  • minnickup
    Greeting,
    I like the way you set up that your softinquiry.com forum is the homepage, nicely done. Thanks!
  • newbie
    I tried copying the code to a new category description but it didn't work... :(

    How is the URL and other required info supposed to be filled in for a hosted forum like one at forumup.com for example?
  • ramirez
    Hello
    as asked befor from Kristoffer, is there a way to show latest posts based on users permissions, i.e. a group with no permissions on a specific forum can't see posts, but logged users with permissions on that forum can see
    Thanks
  • vidineca
    Nicely done! How to show image + text from the last post ? What should be added to the script ?
  • Nicely done! And yes, it works with the latest phpbb3 stable version as of this writing!
  • Hi.
    Is there a way to limit character to 20 or so in a way that it doesn't occupy a second line?

    Thanks!
  • Well right now I don't understand this enough to do it myself. So I'll have to put it on the back burner for now. I have mountains more to learn it seems *laugh* Off to make dinner for my wife and kids. Thanks for the help and insight!
  • lol nor do I....I just started learning this stuff about a week ago. Looking at the database now to try and figure stuff out. >.>
  • MX
    the problem you will get is all formatting will probs be lost. if the post is simple text then im sure there is a field in the table you can pick instead of the topic one which would get you the content, you can probs guess it from the column names of the database table. Think thats the best i can suggest. I havnt a clue how it would handle links / pics etc
  • Could the above code be modified to display the content of the post as well? (body of the post) If that could be done that might just solve my problem. *laugh* It's a great code and I am using it. But I'd like to have a specific section of my forums only show up and then the whole post not just the title and person posting. While I'm at it....would probably be best to have it displayed to those members that have access to said section only. O.o High hopes perhaps but it's what I'm aiming for *laugh* I thank you greatly for the help!
  • I want the body of the post to display. Like
    News header
    Arlack's crabby because he can't figure this out
    lol Not finding alot of current issues with people dealing with this. And my programmer friend has been to busy working to help me out.
  • MX
    you can adjust the number of posts it shows down to 1 if you like in the config file. I dont know nuke though so dont know how you would add it there
  • Yeah I got it all fixed. The main problem I was having was having the file .html instead of .php *laugh* I'm very new to this. What I've been scouring the net for though is a script that will post just one post from my forums (The newest) from a specific place. Like news. Or one that could take say phpnuke news and post it on the forums and the site, or one that takes phpbb3 news post and puts it on nuke. I found one that will pull the nuke news to my site, But I'm not actually using nuke right now (just testing) Any suggestions? I havn't been able to find anything yet.
  • MX
    hey arlack, sounds like you have the url path line set wrong in the top of the php script. you need to make it reflect where your forum is located.

    Im not sure about the specific forum posts bit though
  • Greetings. Love the script but I'm having some issues. I'm new to making my own website so I guess I need more help then some. I have it showing my newest posts but for some reason when I click on the post name or posters name it says "Page not found" Also would like to know if there is a way to post specific topics based on users access rights. Thanks so much for the help.
  • Hello, does this script work with user permissions. Say i want latests post from one forum that is seen only by certain permissions, when logged in. When they are logged out or visiting as guests, they see another site.

    Or did i just give you an idea and improvement? :)
  • Hi Dan, thanks for this script. One problem I'm having is that it's interfering with WordPress 2.6.

    I'm calling this script from the header in WP, but below -- when it's time to get the WP post -- WP gets confused and throws up a
    "Not Found
    Sorry, but you are looking for something that isn't here."

    WP tables and phpBB3 tables are in the same db, with different prefixes of course.

    I thought it was a variable collision, so I changed all variables in the script from $query to $latestpostsquery, $row to $latestpostsrow, etc. Still not working. Any ideas?

    The script works fine in the WP footer.
  • Axel
    Hello. I have some topics naped in Russian, what can I do with incorrect processing of utf-8 with your script? Topic titles appear as incorrect craracters.
    Please advice.
  • @ DJMX

    Its a PHP script. not html. either i frame it or place it in a php script.

    dinlow.
  • iv cut the code from the top of this page and put it on a simple page but it comes up with errors. the page iv got it on for my test is http://www.krisisdnb.com/newforum/malcs1.html

    iv changed the path at the top of the script to /newforum as it says I should but cant work out whats wrong.

    Any ideas?
  • venkat
    Thanks for providing the very useful script
  • mrtruckster
    Hello this is Mike from houston, you got a nice forum here with some good topics and I hope you can help me with some tehnical problems 
    When I start my webbrowser, Im using internet explorer its some weird search engine. It used to be google and everytime I change
    it back to google its okay. Until I start me pc again, then the wrong search engine is back. How can I get rid off this? Its getting annoying
    and there hase to be a way right? 

    Please help me, Im kind of low on budget and wouldnt like to take the computer to an expert and pay a lot of cash for it, all the ideas are welcome
    and I will definetly try them! Hope to hear from you soon!
  • Remco
    Hi,

    I've got a lot of private forums on my site, and am trying to make the excluded-forum list dynamic..

    I do have a produced a query that lists all forum_id's I want to include in this latest-post thing, however, I'm not sure how to combine / join this query to your query, which should result in exactly the data I want to have ;-)

    Any suggestions on how to do this?

    $query = "SELECT phpbb3_acl_groups.forum_id
    FROM `phpbb3_acl_groups` , `phpbb3_groups`
    WHERE phpbb3_groups.group_name = 'GUESTS'
    AND phpbb3_acl_groups.auth_setting =0
    AND phpbb3_acl_groups.group_id = phpbb3_groups.group_id
    GROUP BY forum_id";
  • Hi you lot seem to know want you are doing and have success, I am thinking what do you do with the script? where do you place it? is it compatable with the latest phpbb3?
    many thanks for any idea`s as I would love to have this up and running!
    cheers all
    mrix
  • HSN
    Dears,
    I'm newbie in this field. Can you tell me where i'll paste this script? please email me at hassan(dot)latif(dot)mughal(@)gmail(dot)com

    Thanks in Advance
    HSN
  • admin_papa
    Hi Folks!

    Just wanted to share my new experience.

    If your system fails to start due to an error related to lost HAL.DLL, invalid Boot.ini or any other critical system boot files you can fix this by using the XP installation CD. Simply boot from your XP Setup CD and enter the Recovery Console. Then launch "attrib -H -R -S" on the C:\Boot.ini file and delete it. Launch "Bootcfg /Rebuild" and then Fixboot

    Cheers,
    Carl
  • Stefan
    This script is really great! I love it and want to implement it.
    There is just one little problem:
    My site is in traditional Chinese. I use phpbb3 and the topics are encoded in charset uft-8 in the database. My html header has the charset big5. the result is that if the script runs all topics are show in questionmarks. Is there a way to change the charset during the php output?
    Thanks, Stefan
  • George
    Sweet thanks!
  • George
    Sorry I read it but I'm a little confused about hiding it.
  • Dan
    Yes, of course George. Just have a look at line 23. All you need to do is to find out the corresponding forum id and then write it there. The "!=" operator tells the script to skip that forum.
  • George
    Is it possible to exclude some forums from displaying the latest posts?
  • Kamlesh
    Thanks

    I made a few changes, since I need horizontal scrolling without post by and Date.
    It's works fine.
    Thanks
    <?php
    // How Many Topics you want to display?
    $topicnumber = 5;
    // Scrolling towards up or down?
    // $scroll = "up";
    // Change this to your phpBB path
    $urlPath = "http://draftcraft.in/forum";

    // Database Configuration (Where your phpBB config.php file is located)
    include '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 "";

    while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {

    echo "" .
    $row["topic_title"] .
    "
    ";
    }

    print "";
    mysql_free_result($result);
    mysql_close($link);
    ?>
  • Speets
    Since I have a login script incl cookies on all my pages, I think that's not the problem. It should only require the actual query. Maybe that's something you can help me out with ?
  • Dan
    @Kamlesh, check this out. I hope it is an inspiration.
    @Speets, sorry but I didn't had time to modify the script. For the next step I think that you will need to create a query that will ask the database which topics are unread for a certain user that will have to be logged in (the login information will have to be at hand for the query).
  • Kamlesh
    Thanks for a Great Script.
    I want topics in Horizontal scrolling . can u suggest the changes.
  • Speets
    Surprisingly, I done it myself. Got the replies text working. Now I just need to do it so that it shows whether the reply is an unread one, or a read one. IE "Latest post standalone script by Kevin (*3)

    with 3 indicating the replies, and the * indicating whether it's new.

    Any ideas?
  • I don't get why the script does not work for me. I keep getting some of the code being displayed as text on the front end. I changed the paths required for login and forum info, but am still having problems. Please advise if I need to change certain periods to semi colons or something of that nature.
  • Mile
    Hello, is there any way we can use simple html and css for layout?? cause i cant modify it like this.. few other people complained too but VERY GOOD SCRIPT! Thanks and please help!
  • speets
    Dear Dan,

    Did you ever got around to helping me and answering my question ?

    Looking forward to an answer.

    Kind regards,
    Speets
  • Dan
    Hello doug. No comments are left behind but comments moderation is activated. And to answer you question, to disable the scrolling effect you would probably want to remove the whole marquee code and frame its content in a div or span.
  • doug thrower
    Hi, I posted but a comment but it seems to have gone away. Basically, this script is great, but I just wondered if there was a way to make it static.

    Cheers,
  • doug
    This is great, but if I didn't want it to scroll, how would I modify the script?
  • speets
    Fred and Chris:
    - Make a new HTML page (or implent it into an existing one)
    - Paste the code displayed above in the HTML
    - in the code, there's a line " include 'forum/config.php'; ", that needs to be the path to your PHPBB config.php. So, if for example you have put your HTML file with this script in your actual PHPBB directory; all you need to do then is change " include 'forum/config.php'; " to " include 'config.php'; "

    hope that made sense.
    -Speets
  • fred
    Hi, how does one install this script?
  • Chris
    How do I install this?
  • Dan
    Hello again. As you probably noticed I didn't had time to post on my blog another article since. Currently I have to finish another web project that will actually serve as a certificate. After that I will need to study hard for about 1 month because I will finish my studies at this school and graduate. Hopefully I will find some time to have a look at this script and adjust the query so that it will suit your needs.
    Cheers.
  • speets
    Dear Dan,

    Did you get any time to work any further on this project ?

    Kind regards
  • speets
    Thanks in advance!

    One more thing that's only an optional thing, so not too important, but I was wondering if it's possible to change the order from "most recently active post" to "date topic posted"
    again, it's not that important and I understand if it's too much hassle.

    The reply thing is more important and I'd really appreciate your help.

    Thanks in advance

    Kind regards,
    Speets
  • Dan
    Hello speets. Thanks for your appreciation. Currently I have some stuff to attend to but I promise i will post a comment with a solution for you when I'll have some free time.
  • speets
    if you have a solution for me, please cc your answer to unknown (@) kaille.com
    muchos thanks !
  • speets
    Thanks for the script, it works great. I was wondering, is there any way to make it display the amount of replies on a thread?
    kind of like: | Thread topic name (10) | by Softinquiry | April 12, 2008, 8:26 pm
    with (10) being the amount of posts in that specific topic.

    If you know a solutions for this please notify me. Thanks in advance!

    Kind regards
  • Dan
    Thanks Mattias, truly appreciated.
  • Pure excellence! Thanks!
blog comments powered by Disqus