Log in

View Full Version : How to dispay latest threads on homepage?


Bonee70
10-16-2003, 12:08 PM
Ive already searched the forums for a script but I cant find any help here so far.

Im looking for an oportunity to display the lastest threads on my homepage.

It should look like this:

http://playaz.elitemaddenleagues.com/

I guess even the homepage of this site is using those scripts.

Help or a hint would be very appreciated!

Bonee

paddysplace
10-16-2003, 04:10 PM
<?php
error_reporting(7);

chdir('/home/USERNAME/public_html/forums');

require('./global.php');

###########
## Stats ##
###########

////Get number of members
//$totalmembers
$numbersmembers=$DB_site->query_first('SELECT COUNT(*) AS users,MAX(userid) AS max FROM user');
$totalmembers = number_format($numbersmembers['users']);

////Get total number of posts
//$totalposts

$countposts=$DB_site->query_first('SELECT COUNT(*) AS posts FROM post');
$totalposts = number_format($countposts['posts']);

////Get total number of threads
//$totalthreads

$countthreads=$DB_site->query_first('SELECT COUNT(*) AS threads FROM thread');
$totalthreads = number_format($countthreads['threads']);

////Get username and id of newest member
//$newestuser[user]
//$newestuser[id]

$newestuser=$DB_site->query_first("SELECT userid,username FROM user WHERE userid=$numbersmembers[max]");
$newestuser[user] = unhtmlspecialchars($newestuser['username']);
$newestuser[id] = unhtmlspecialchars($newestuser['userid']);

////Get username, id, post count, and post percent of top poster
//$top[user]
//$top[id]
//$top[count]

$topposter=$DB_site->query_first('SELECT userid,username,posts FROM user ORDER BY posts DESC LIMIT 10');
$top[user] = unhtmlspecialchars($topposter['username']);
$top[id] = unhtmlspecialchars($topposter['userid']);
$top[count] = number_format($topposter['posts']);

###################
## Testing Stats ##
###################

echo "<font face=arial>";
echo "Total Members: "."<b>$totalmembers</b>";
echo "<BR>";
echo "Total Posts: "."<b>$totalposts</b>";
echo "<BR>";
echo "Total Threads "."<b>$totalthreads</b>";
echo "<p>";
echo "Newest User Username: "."<b>$newestuser[user]</b>";
echo "<BR>";
echo "Newest User ID: "."<b>$newestuser[id]</b>";
echo "<p>";
echo "Top Poster Username: "."<b>$top[user]</b>";
echo "<BR>";
echo "Top Poster ID: "."<b>$top[id]</b>";
echo "<BR>";
echo "Top Poster Count: "."<b>$top[count]</b>";
echo "<p><br>";

#########################
## Latest Forum Topics ##
#########################

echo "Last 5 Thread Postings:<p>"; //Seperate from Stat Display

$maxthreadchars = "30";

$threads=$DB_site->query("SELECT threadid,thread.title,replycount,postusername,post userid,dateline,views,lastposter,lastpost FROM thread ORDER BY lastpost DESC LIMIT 5");
while ($thread=$DB_site->fetch_array($threads))
{
$lastposttime = vbdate("$timeformat $dateformat",$thread['lastpost']);
$title = unhtmlspecialchars($thread['title']);

if (strlen($thread['title'])>"$maxthreadchars" AND $maxthreadchars!='0')
{
$title = substr($thread['title'], 0, $maxthreadchars - 3) . '...';
}
$thread['date'] = vbdate("$dateformat $timeformat", $thread['dateline']);
?>
<table bordercolor="#000000" border="1" cellspacing="0" cellpadding="3">
<tr>
<td>
<B><? echo $title; ?></B>
</td>
</tr>
<tr>
<td>
<font size="-1">
Reply Count: <B><? echo $thread['replycount']; ?></B><br>
Thread Starter: <B><? echo $thread['postusername']; ?></B><br>
Total Views: <B><? echo $thread['views']; ?></B><br>
Last Poster: <B><? echo $thread['lastposter']; ?></B><br>
Thread Date: <B><? echo $thread['date']; ?></B><br>
</font>
</td>
</tr>
</table><p>
<?
}
$DB_site->free_result($threads);
unset($thread);
?>


Compatible with 2.x, Use whatever you'd like from it.. I was bored, output viewable at http://www.mesopia.com/vbstats.php

Regards,
Patrick

Bonee70
10-17-2003, 12:01 PM
Oh greta man, ty! ...but for some reason I cant view the code (liscense reasosn?). Well I have my code here, but what to do now?!

Sylvus
10-17-2003, 03:40 PM
This is a great little addition you made Patrick! Any way to make it the last 5 posts per forum category?

Syl...

hypnoticpimp
06-16-2006, 02:36 PM
i use vbulletin 3.5.4

and i get ths error

Unable to add cookies, header already sent.
File: /home/wshh/public_html/home1.php
Line: 7

when using that

Marco van Herwaarden
06-17-2006, 12:10 PM
i use vbulletin 3.5.4

and i get ths error

Unable to add cookies, header already sent.
File: /home/wshh/public_html/home1.php
Line: 7

when using thatMake sure there is no extra character (or space/newline) in front of the "<?php", or after the final "?>" in any PHP-file.

Make sure you are using an editor that can handle this correct.

hypnoticpimp
06-20-2006, 10:57 PM
marco. theres no space betweeen that, and when i access my page. vbstats.php i get this error

Fatal error: Call to a member function query_first() on a non-object in /home/wshh/public_html/vbstats.php on line 14

I just copied and pasted that whole php code to notepad, and changed location of my global file. and uploaded it and i got that error