Topic: Phpbb3 latest posts on your homepage. Customizable.
Hello.
This modification shows phpbb3 latest post on your homepage.
It's working very fine on my site since I added it in september 2010.
(Another modification you may be interested in is here: >>> MODIFICATION TO PERFECTLY INTEGRATE A PHPBB3 FORUM INTO VLDPERSONALS <<<).
This modification allows you to set:
a) how many latest posts to display
b) how many characters of each post to display
c) the forums you want to exlude from showing in home page using forum IDs (useful for private/hidden/moderators sections of your forum)
NOTE: This has been created for vldpersonals 2.5.6 and for template REDLOVE. It worked on phpBB 3.0.7 PL1 and it's working on 3.0.8.
I don't know if it works on newest vldp versions and maybe you have to customize it to fit your own template.
IMPORTANT: I don't want to be responsible for any damage to your website and database.
So, REMEMBER TO BACKUP BEFORE YOU TRY.
After you try, please post your feedback to say if it works with vldpersonal versions after 2.5.6 and other templates than RedLove.
This will help other people to use and customize it.
1) Create a new file and name it latest_posts.php
2) Copy and paste into it the following code:
<?php
// error_reporting(0);
define('IN_PHPBB', true);
include_once (''); //Path to phpBB Config File. Due to some restrictions by PHP, you have to provide complete physical path
$urlPath = ""; //phpBB URL with respect to root
$topicnumber = ; //Total Post Count to Display
$posttext = ; //Number of Characters to display in Post Text
$excludedforums = ""; //Forum ids to exclude. Each forum id should be seprated with Comma
$completeurl = "";
$table_topics = $table_prefix. "topics"; //Usually you don't have to change below 4 variables
$table_forums = $table_prefix. "forums";
$table_posts = $table_prefix. "posts";
$table_users = $table_prefix. "users";
function stripBBCode($text_to_search) {
$pattern = '|[[\/\!]*?[^\[\]]*?]|si';
$replace = '';
return preg_replace($pattern, $replace, $text_to_search);
}
$link = mysql_connect("$dbhost", "$dbuser", "$dbpasswd") or die("Could not connect");
mysql_select_db("$dbname") or die("Could not select database");
$sub_query = '';
if(strlen($excludedforums) > 0) {
$pieces = explode(",", $excludedforums);
foreach ($pieces as $exforumid) {
$sub_query .= " t.forum_id != " . $exforumid . ' AND ';
}
}
$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, f.forum_name, p.post_text, p.bbcode_uid, p.bbcode_bitfield, f.forum_desc_options
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 ";
if(strlen($sub_query) > 0) {
$query .= $sub_query ;
}
$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";
//echo $query;
$result = mysql_query($query) or die("Query failed" . mysql_error($link));
print "<div class=\"typecontent\">";
if($topicnumber % 2) {
$x="even";
} else {
$x="odd";
}
$y=0;
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
++$y;
if ($y==$topicnumber) {
$x= $x . " dataitemlast";
}
print "<div class=\"dataitem $x \">
<table class=\"plain\">
<tr>
<td class=\"data\">
<div class=\"itemheader\">
<h2 class=\"inner\">" . $row["topic_title"] . "</h2>
<ul class=\"itemheader\">
<li>Posted at: " . date('F j, Y, g:i a', $row["post_time"]) . "</li>
<li>By: <a href=\"$completeurl/$row[username]\">" .
$row["username"] . "</a></li> <li>In Forum: " . $row["forum_name"] . " </li>
</ul>
</div>
<div class=\"entry\">" .
substr(stripBBCode($row["post_text"]),0,$posttext) . "<a href=\"$urlPath/viewtopic.php?f=$row[forum_id]&t=$row[topic_id]&p=$row[post_id]#p$row[post_id]\" style=\"text-decoration:none;font-weight:bold\"> Read more...</a>
</div>
</td>
</tr>
</table>
</div>";
if ($x=="odd") {
$x="even";
} else {
$x="odd";
}
}
print "<div class=\"clear\"></div></div>";
mysql_free_result($result);
// mysql_close($link);
?>3) Customize the file latest_posts.php this way:
>>> Set the following rows (from #5 to #10)
include_once (''); //Path to phpBB Config File. Due to some restrictions by PHP, you have to provide complete physical path.
$urlPath = ""; //phpBB URL with respect to root
$topicnumber = ; //Total Post Count to Display
$posttext = ; //Number of Characters to display in Post Text
$excludedforums = ""; //Forum ids to exclude. Each forum id should be separated with Comma
$completeurl = "";
>>> EXAMPLE
include_once ('/home/mysite.com/public/phpbb3/config.php'); //Path to phpBB Config File. Due to some restrictions by PHP, you have to provide complete physical path
$urlPath = "/phpbb3"; //phpBB URL with respect to root
$topicnumber = 5; //Total Post Count to Display
$posttext = 200; //Number of Characters to display in Post Text
$excludedforums = "1,3,8,14"; //Forum ids to exclude. Each forum id should be separated with Comma
$completeurl = "http://www.mysite.com";
>>> NOTE: For the correct fisical path to phpBB config file, check to your web host.
4) upload the file latest_posts.php into your template folder (e.g.: /templates/webby2/)
5) open templates/YOURTEMPLATE/homepage.tpl (e.g.: /templates/webby2/homepage.tpl)
6) add the following script where you want to add latest forum posts
<h3 class="blogs">Latest Forum Posts</h3>
<div class="block blogs">
<!-- INCLUDE latest_posts.php -->
</div>
7) ENJOY!
8) Remember to add your feedback into this forum. (Does this modification work on your vldpersonals version and within your template?)
Last edited by orange_slice (2011-02-14 02:31:11)