How to show latest phpBB3 posts in your WordPress sidebar

As you may notice, at the top of the rightmost column of this blog I am showing the latest posts of the forum.

I did not find any widget fitting my needs so I had to solve the problem by myself. And I am going to tell you how.

At the moment it's not a widget, just a bunch of lines in a PHP Code Widget to do the trick. Should I receive good feedback, I will develop a fully customizable widget.

Anyway, following this tutorial will make you able to show your phpBB3 posts in your WP sidebar in a matter of minutes.

First, in your WP admin area go to Presentation -> Widgets to go into Sidebar Arrangement section.

You should find a screen like this one

WP admin area

... but it may be a bit different according to your theme. Anyway, what you need is a PHP Code Widget, so have to create one (look at the bottom arrow in the image) and drag/drop it in the sidebar.

Then you're ready to enter the code in your widget:

PHP:
  1. <?php
  2. $connection = mysql_connect(localhost,"your_login","your password") or die("Service temporairly unavailable");
  3. $db = mysql_select_db("your_db_name",$connection) or die("Service temporairly unavailable");
  4. $sql = "select * from phpbb_topics order by topic_last_post_time desc limit 0,10";
  5. $result = mysql_query($sql) or die("Service temporairly unavailable");
  6. for($x=1;$x<=10;$x++){
  7.     $row = mysql_fetch_array($result);
  8.     echo "<a href = \"http://www.yourforumdomain.com/viewtopic.php?f=$row[forum_id]&t=$row[topic_id]\" target = \"_blank\">$row[topic_title]</a><br>";
  9. }
  10. ?>

Line 1: Opening php tag. Normally it makes no difference between <? and >?php but my widget told me

PHP Code MUST be enclosed in tags!

Line 2: Connecting with the database where you are hosting your phpBB3. Change localhost with the address of your database, your_login with database login and your_password with your database password. In case something should fail (database is down, login or password are incorrect), I return a "Service temporairly unavaiable" and terminate the script.

Line 3: Selecting the database where you installed your phpBB3. Change your_db_name with the name of the database.

If you do not remember one (or more) data explained at lines 2-3, simply give a look to your config.php file in the folder where you installed phpBB3.

It's made in this way:

PHP:
  1. <?php
  2. // phpBB 3.0.x auto-generated configuration file
  3. // Do not change anything in this file!
  4. $dbms = 'mysql';
  5. $dbhost = '122.122.122.122';
  6. $dbport = '';
  7. $dbname = 'emanuele';
  8. $dbuser = 'triqui';
  9. $dbpasswd = 'banana';
  10.  
  11. $table_prefix = 'phpbb_';
  12. $acm_type = 'file';
  13. $load_extensions = '';
  14.  
  15. @define('PHPBB_INSTALLED', true);
  16. // @define('DEBUG', true);
  17. // @define('DEBUG_EXTRA', true);
  18. ?>

At line 5 you will find the database address (122.122.122.122), at line 7 db name (emanuele), at line 8 db username (triqui) and at line 9 the password (banana).

Also remember line 11 and write down somewhere the content of table_prefix variable (phpbb_)

I did not used any of those names, so don't even try to hack my forum... but let's go back to the script...

Line 4: This is the string representing the query that will create the table with the last 10 updated topcis. phpbb_topics is the name of the table than contains the topics. If you have another value in your table_prefix variable, then you will need to change phpp_topics with your_table_prefix_topics. So, as an example, if your table prefix is triqui, then your table name will be triqui_topics, while you won't have to change topic_last_post_time that represents the timestamp of the last post in the topic. In this way, you will get a table with the latest 10 topic ordered by last post time. If you want more (or less) than 10 topics, change the 10 in limit 0,10

Line 5: Processing the query, or returning in case of error the same fake message "Service temporairly unavaiable"

Line 6: Loop to be executed 10 times

Line 7: Fetching the row of the table in an array called row

Line 8: Displaying the link: notice that the link starts with http://www.yourforumdomain.com/, you will have to change this address with the path of your phpBB3 forum. For instance, if your forum is in the forum folder in the google domain, you will have to write http://www.google.com/forum/. You don't need to change anything else

That's all. Hope you will find it useful... maybe some day I will make a widget that will be easier to configure.

Improve the blog rating this post
Tell me what do you think about this post. I'll write better and better entries.
1 Star2 Stars3 Stars4 Stars5 Stars (6 votes, average: 4.33 out of 5)
Loading ... Loading ...

» WordPress themes are designs for WordPress - one of the most popular blogging software nowadays.
You will be pleasantly surprised by WordPress Themes provided by Template Monster. All of them are of professional design and high quality.

29 Responses to “How to show latest phpBB3 posts in your WordPress sidebar”

  1. RJ on February 8th, 2008 5:52 pm

    I know a guy who used this in his page…
    I think he was called Emanuele… and it was very cool to see the latest posts without having to go to the forum, I think you should use it, Emanuele

    ;)

  2. Sunil Patel on February 8th, 2008 7:11 pm

    Sorry to be fussy, but you put: or die(”Service temporairly unavaiable”);
    There is a typo, should be: available.
    Anyway, great idea - its really useful!

  3. Emanuele Feronato on February 8th, 2008 8:25 pm

    Thanks. Fixed.

  4. andrew on February 10th, 2008 2:48 pm

    Hi Emanuele, I have recently been making a game based on your ball game with visual from above tutorial. I would like you to put it on your website if that is possible. I have changed the background and the tiles, and have made some types of my own. These include the “rollercoaster tiles” which hurtle you in the direction they are pointing, and a few other surprises. Your tutorials are brilliant and without them I would really be stuck with actionscript.

  5. Graham Kaemmer on February 10th, 2008 7:16 pm

    I am making a website, but I don’t know how to get my phpBB posts/topics into my mySQL server. How do I do this? Did you already show how?

    Thanks a bunch.

  6. Pinoylandia on February 11th, 2008 10:34 am

    thanks to this post. it’s my first time to see that it you can show the latest forum posts on my blog. :)

  7. Monkios on February 13th, 2008 6:58 pm

    It doesn’t make you lose a lot of time but since it is MySQL, you could put “Limit 0, 10″ at the end of your query.

  8. Emanuele Feronato on February 13th, 2008 7:02 pm

    That’s what I did, Monkios

  9. chris on February 14th, 2008 12:53 am

    I am having issues with this. I implemented exactly how you stated and the widget works fine and does display the latest forum posts but all the other widgets below this widget in my sidebar are no longer displaying their data. Any idea why?

  10. stef on February 20th, 2008 12:20 am

    I have the problem that i see the title of the widgetfine but not any latest topics?? any tricks to fix?

  11. Hijack on February 24th, 2008 6:07 pm

    I get this error

    Parse error: parse error, unexpected T_STRING in /home/content/html/example.php on line 7

    Which is this line:

    $row = mysql_fetch_array($result);

    Could you help me?

  12. Tyler on February 24th, 2008 8:49 pm

    Hi Emanuele -

    This is great!! This helped me out a ton, thank you so much!

    I have multiple phpbb3 boards running out of one database (I use different prefix’s to distinguish them all).. Can you think of a way to modify your code so that I can display the past 10 topics out of all of my boards, and not just one specific prefix?

    I appreciate your help!

  13. Tyler on February 24th, 2008 9:54 pm

    Hello again,

    I was actually able to figure out how to select the correct topics using the following SQL statement:

    select * from prefix1_topics
    UNION ALL
    select * from prefix2_topics
    UNION ALL
    select * from prefix3_topics
    order by topic_last_post_time desc limit 0,10

    Is that the best way to accomplish this?

    Now I cannot seem to figure out a way to direct the users after they click on a topic to the correct board. In other words I need to somehow modify your line to the appropriate board:

    echo “$row[topic_title]“;

    The problem I am having is in the bottom section where I am trying to link to the correct topic. I cannot figure out a way to have the topic link to the correct board. How can I make it so that http://prefix.mysite.com matches the correct prefix from my SQL query?

  14. tanketom on March 12th, 2008 7:42 am

    Hi and thanks for the code. Helped me, both from tearing the hair off my head and a lot of time to make this myself.

    Just wondering about one thing. I’ve got part of a forum that is hidden from “normal users” (an admin forum), and this comes up on the frontpage! Would it be possible to attach some code that makes only “visible” forums appear on the frontpage?

    Thanks in advance!

  15. Floroskop on March 18th, 2008 12:00 pm

    Hello!
    I think this try.

  16. Paul on April 7th, 2008 3:55 am

    Hi, great mod, but I have the same query as tanketom. How do I prevent titles of posts in private forums from being displayed?

    I know it can be done, as I have mods within phpBB that do exactly that, but my knowledge of php isn’t good enough to port the code across into a Wordpress sidebar. :-(

  17. FrozenHaddock on April 7th, 2008 7:26 pm

    Would this work for Phpbb2?

    We’re having issues with 3…

  18. hellows on May 4th, 2008 6:06 pm

    Wow. It is working. Well done. I am so happy now. I have been looking for this for a long time.

    NOTE: This php is working for 2.5+ worspress but you must istall a php widget plugin so that you can use this code.

    PS: How can I get the topic names to change color when I roll over them with a mouse. something like a flash highlight ?

    Congratulations one more time!

  19. hellows on May 4th, 2008 6:08 pm

    UPDATE. Make a widget out of it or a plugin. This will be so popular eith the WP users as all other plugins in the WP plugin section are not wotking.
    + make the phpBB use the WP databes so a user will have to only login once. This will be so popular. thanks :>

  20. Jimmy on May 8th, 2008 9:41 am

    I have the problem that i see the title of the widgetfine but not any latest topics?? any tricks to fix?

  21. Dudebuddy on June 3rd, 2008 6:28 pm

    You also spelled “temporarily” wrong…

  22. Jai on July 3rd, 2008 8:50 am

    lol, banana.

  23. Mithun on August 4th, 2008 7:49 am

    hi ,
    I have similar problem.
    I want to add some information from my forum to be displayed on my homepage.
    Information is like current user , latest member name etc ..
    I dn’t kno how to do it ..
    can you help me…

    one more thing , in your given code , what will happen if topics are less than 10 ??

  24. Jonathan Cremin on August 6th, 2008 12:54 pm

    use
    while ($row = mysql_fetch_array($result)){
    echo “forum post link”;
    }
    instead.

    Also, instead of putting numbers alongside your code, use and ordered list to achieve the same effect without us having to delete it from your code.

  25. Ed on September 2nd, 2008 2:17 am

    Thanks for the small snippet of code that allowed me to not do any work. :) Using it on http://www.hiptop3.com in the sidebar.

  26. Chris on September 24th, 2008 7:28 pm

    this code just destroyed my site. I also cannot remove the widget anymore in my Dashboard.

    Please help fast.

  27. werutzb on October 7th, 2008 2:03 am

    Hi!

    I would like make better my SQL capabilities.
    I red so many SQL resources and still feel, that I am not an expert
    in SQL. What would you recommend?

    Thanks,
    Werutz

  28. HSCharles on November 14th, 2008 5:23 am

    I have a flash site
    i’m looking for the script who of google ads on flash.
    how can i get it?

  29. selleriee on November 17th, 2008 8:33 pm

Leave a Reply