# phpBB3 latest forum posts on frontpage

**URL:** <https://forum.phpvms.net/t/phpbb3-latest-forum-posts-on-frontpage/5488>\
**Category:** Code Snippets\
**Created:** [October 9, 2011, 11:18am UTC](https://forum.phpvms.net/t/phpbb3-latest-forum-posts-on-frontpage/5488 "2011-10-09T11:18:32Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Angel\_Air](https://forum.phpvms.net/letter_avatar_proxy/v4/letter/a/f05b48/32.png) [@Angel\_Air](https://forum.phpvms.net/u/Angel_Air)\
**Post date:** [October 9, 2011, 11:18am UTC](https://forum.phpvms.net/t/phpbb3-latest-forum-posts-on-frontpage/5488/1 "2011-10-09T11:18:32Z")

</div>

Hi all,

Does anyone have the code for displaying phpbb3 latest forum posts on the frontpage? also is there a auto register code for phpbb?

thanks in advance

Scott

---

<div class="post-metadata">

**Author:** ![Angel\_Air](https://forum.phpvms.net/letter_avatar_proxy/v4/letter/a/f05b48/32.png) [@Angel\_Air](https://forum.phpvms.net/u/Angel_Air)\
**Post date:** [October 18, 2011, 4:57pm UTC](https://forum.phpvms.net/t/phpbb3-latest-forum-posts-on-frontpage/5488/2 "2011-10-18T16:57:44Z")

</div>

> I got my phpBB3 to support rss feeding and viewed the RSS feed in the website.

Ok so how do I get the forum to produce a RSS feed and then how do I implement it on the frontpage?

---

<div class="post-metadata">

**Author:** ![flyalaska](https://forum.phpvms.net/user_avatar/forum.phpvms.net/flyalaska/32/14_2.png) [@flyalaska](https://forum.phpvms.net/u/flyalaska)\
**Post date:** [May 10, 2012, 4:38am UTC](https://forum.phpvms.net/t/phpbb3-latest-forum-posts-on-frontpage/5488/3 "2012-05-10T04:38:44Z")

</div>

I know this an old post. I have the code if anyone needs it.

---

<div class="post-metadata">

**Author:** ![Kyle](https://forum.phpvms.net/letter_avatar_proxy/v4/letter/k/848f3c/32.png) [@Kyle](https://forum.phpvms.net/u/Kyle)\
**Post date:** [May 10, 2012, 11:54am UTC](https://forum.phpvms.net/t/phpbb3-latest-forum-posts-on-frontpage/5488/4 "2012-05-10T11:54:34Z")

</div>

> I know this an old post. I have the code if anyone needs it.

been looking for one for a while. yes please, could I have the code please?

thanks!

---

<div class="post-metadata">

**Author:** ![mseiwald](https://forum.phpvms.net/user_avatar/forum.phpvms.net/mseiwald/32/149_2.png) [@mseiwald](https://forum.phpvms.net/u/mseiwald)\
**Post date:** [May 10, 2012, 2:00pm UTC](https://forum.phpvms.net/t/phpbb3-latest-forum-posts-on-frontpage/5488/5 "2012-05-10T14:00:06Z")

</div>

Me too please…that would be Great

(null)

---

<div class="post-metadata">

**Author:** ![flyalaska](https://forum.phpvms.net/user_avatar/forum.phpvms.net/flyalaska/32/14_2.png) [@flyalaska](https://forum.phpvms.net/u/flyalaska)\
**Post date:** [May 10, 2012, 3:40pm UTC](https://forum.phpvms.net/t/phpbb3-latest-forum-posts-on-frontpage/5488/6 "2012-05-10T15:40:21Z")

</div>

name it recent\_post.php. Replace URL to your forums with the url, leave the backslash. Upload it to your forum directory.

```
<?php
// Sets the number of topics to display
   $topicnumber = 5;

   // Change this to your PHPBB3 path (no trailing slash "/")
   $urlPath = "URL to your forums/";

   // Database configuration (where your PHPBB3 config.php file is located)
   include 'config.php';

// Database connection and error messages
   $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");

// Main database query
   $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

/ **********************
 ***********************
EXCLUDE THESE FORUM IDs (if you have private forums)
***********************
 ********************** /
   t.forum_id != 17 AND
t.forum_id != 19 AND
t.forum_id != 20 AND
/ **********************
 ***********************
END EXCLUSIONS
***********************
 ********************** /

/* Back to the query... */
   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"); 

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

// HTML parsing
   echo "<a href=\"$urlPath/viewtopic.php?f=$row[forum_id]&t=$row[topic_id]&p=$row[post_id]#p$row[post_id]\" class='topic_new'>" .
   $row["topic_title"] .
   "</a><br /><a href=\"$urlPath/memberlist.php?mode=viewprofile&u=$row[user_id]\">" .
   $row["username"] . "</a> on " . 
   date('M j, Y, g:i a', $row["post_time"]) . "<br /><br />";
   }
   mysql_free_result($result);
   mysql_close($link);
?>

<?php include("forums/latest_post.php"); ?>

```

---

<div class="post-metadata">

**Author:** ![mseiwald](https://forum.phpvms.net/user_avatar/forum.phpvms.net/mseiwald/32/149_2.png) [@mseiwald](https://forum.phpvms.net/u/mseiwald)\
**Post date:** [May 10, 2012, 6:00pm UTC](https://forum.phpvms.net/t/phpbb3-latest-forum-posts-on-frontpage/5488/7 "2012-05-10T18:00:25Z")

</div>

Thank you very much it works great

(null)

---

<div class="post-metadata">

**Author:** ![Zeke](https://forum.phpvms.net/letter_avatar_proxy/v4/letter/z/8e7dd6/32.png) [@Zeke](https://forum.phpvms.net/u/Zeke)\
**Post date:** [June 5, 2012, 5:37pm UTC](https://forum.phpvms.net/t/phpbb3-latest-forum-posts-on-frontpage/5488/8 "2012-06-05T17:37:59Z")

</div>

```
<?php
// Sets the number of topics to display
$topicnumber = 5;
// Change this to your PHPBB3 path (no trailing slash "/")
$urlPath = "URL to your forums/";
// Database configuration (where your PHPBB3 config.php file is located)
include 'config.php';
// Database connection and error messages

$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");
mysql_set_charset('utf8');

// Main database query
$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
/ **********************
 ***********************
EXCLUDE THESE FORUM IDs (if you have private forums)
***********************
 ********************** /
t.forum_id != 17 AND
t.forum_id != 19 AND
t.forum_id != 20 AND
/ **********************
 ***********************
END EXCLUSIONS
***********************
 ********************** /
/* Back to the query... */
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");
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
// HTML parsing
echo "<a href=\"$urlPath/viewtopic.php?f=$row[forum_id]&t=$row[topic_id]&p=$row[post_id]#p$row[post_id]\" class='topic_new' target='_blank'>" .
$row["topic_title"] .
"</a><br /><a href=\"$urlPath/memberlist.php?mode=viewprofile&u=$row[user_id]\" target='_blank'>" .
$row["username"] . "</a> on " .
datum($row["post_time"]) . "<br /><br />";
}
mysql_free_result($result);
mysql_close($link);

function datum($time) {
$ma = mktime(0, 0, 0, date("m"), date("d"), date("Y"));
$tegnap = $ma-(60*60*24);

if($time > $ma) { $datum = "today, " . date("H:i",$time); }
elseif($ma > $time AND $time > $tegnap) { $datum = "yesterday, " . date("H:i",$time); }
elseif($time < $tegnap) { $datum = date ("M j, Y H:i",$time); }

return $datum;
}
?>

```

---

<div class="post-metadata">

**Author:** ![TAV1702](https://forum.phpvms.net/user_avatar/forum.phpvms.net/tav1702/32/41_2.png) [@TAV1702](https://forum.phpvms.net/u/TAV1702)\
**Post date:** [April 8, 2014, 6:05pm UTC](https://forum.phpvms.net/t/phpbb3-latest-forum-posts-on-frontpage/5488/9 "2014-04-08T18:05:34Z")

</div>

I know this is a rather old post and I thank you flyalaska for the script.

What I am wondering is can we make it so that instead of excluding private forums, can we make it check if one is an admin or moderator what ever the private forum is setup to show to? So if and admin or moderator then allow to see the recent private post and if not then continue on to the other posts?

Thanks again for this script. I like how it works and looks decent on my site.

---

<div class="post-metadata">

**Author:** ![TAV1702](https://forum.phpvms.net/user_avatar/forum.phpvms.net/tav1702/32/41_2.png) [@TAV1702](https://forum.phpvms.net/u/TAV1702)\
**Post date:** [October 26, 2016, 3:13am UTC](https://forum.phpvms.net/t/phpbb3-latest-forum-posts-on-frontpage/5488/10 "2016-10-26T03:13:28Z")

</div>

Now I know this post is old as hell but , this old code has quit working due to mysql\_connect() being deprecated. I have tried mysqli\_connect() and PDO and it is a no go all the way around.

Any one still pulling posts on their site?

---

<div class="post-metadata">

**Author:** ![TAV1702](https://forum.phpvms.net/user_avatar/forum.phpvms.net/tav1702/32/41_2.png) [@TAV1702](https://forum.phpvms.net/u/TAV1702)\
**Post date:** [November 1, 2016, 9:53pm UTC](https://forum.phpvms.net/t/phpbb3-latest-forum-posts-on-frontpage/5488/11 "2016-11-01T21:53:48Z")

</div>

No one? I do have a working version on the same exact server setup as my live site but it is a WAMP server. The script on my WAMP works a treat, however, on my live server, it fails miserably.

Here is what I have. Maybe someone has better luck than I with it.

\*\*PLEASE NOTE\*\*

This code is to be used at your own risk. I do not know if it is secure or what. It did come right from phpBB community. I take no credit or ownership.

The WAMP server it is working on is:

Apache

php 5.6.25

mysql 5.7.14

The server it is NOT working on is:

apache

php **5.5.36**

**mysql:**

Include this following code at the VERY TOp of every page in which you wish to call the latest posts.

```
<?php
   define('IN_PHPBB', true);
   $phpbb_root_path = './community/'; // Path to phpbb folder
   $phpEx = substr(strrchr( __FILE__ , '.'), 1);
   include($phpbb_root_path . 'common.' . $phpEx);
   include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
   // Start session management
   $user->session_begin();
   $auth->acl($user->data);
   // Grab user preferences
   $user->setup();
?>

```

Use this where you wish the latest posts to show

```
<?php
   / ***phpBB3 - Last Active Topics System*** /
   //Show last x topics
   define('TOPICS_LIMIT',10);
   // Create arrays
   $topics = array();

   // Get forums that current user has read rights to.
   $forums = array_unique(array_keys($auth->acl_getf('f_read', true)));

   // Get active topics.
   $sql="SELECT *
   FROM " . TOPICS_TABLE . "
   WHERE topic_approved = '1' AND " . $db->sql_in_set('forum_id', $forums) . "
   ORDER BY topic_last_post_time DESC";
   $result = $db->sql_query_limit($sql,TOPICS_LIMIT);
   while ($r = $db->sql_fetchrow($result))
   {
    $topics[] = $r;
   }
  $db->sql_freeresult($result);
?>
<div>
<?php

   foreach($topics as $t)
   {
    // Get folder img, topic status/type related information
    $topic_tracking_info = get_complete_topic_tracking($t['forum_id'], $t['topic_id']);
    $unread_topic = (isset($topic_tracking_info[$t['topic_id']]) && $t['topic_last_post_time'] > $topic_tracking_info[$t['topic_id']]) ? true : false;
    $folder_img = $folder_alt = $topic_type = '';
    topic_status($t, $t['topic_replies'], $unread_topic, $folder_img, $folder_alt, $topic_type);

    // output the link
    ?>
	    <img style="vertical-align: text-bottom" src="<?php echo $user->img($folder_img, $folder_alt, false, '', 'src');?>" title="<?php echo $user->lang[$folder_alt];?>" alt="<?php echo $user->lang[$folder_alt];?>" />
	    <a href="<?php echo $phpbb_root_path . 'viewtopic.php?f=' . $t['forum_id'] . '&t=' . $t['topic_id'] . '&p=' . $t['topic_last_post_id'] . '#p' . $t['topic_last_post_id'];?>"><?php echo html_entity_decode($t['topic_title']);?></a><br />
   <?php
   }
   ?>
</div>

```
