是我在網路上問人然後自己修改成功後 跟大家分享
首先要先裝eXtreme styles這個外掛這樣才可以在.tpl執行php
第二步驟:
因為我的論壇是用phpbb 首頁是裝EZportal外掛
所以以下這段code我裝在 portal_body.tpl 裡面
有一些你得再修改,像是資料庫的名字、密碼、路徑,還有看你要怎麼資料就再加進去!
<table width="100%" cellpadding="2" cellspacing="1" border="0" class="forumline">
<tr>
<td class="catHead" height="25"><span class="genmed"><b>隨機圖片</b></span></td>
</tr>
<tr>
<td class="row1" align="center">
<?php
//<?php
//***Enter Path information here***
//***absolute path to main coppermine directory***
$copperminepath = './your_path'; //***YOU MUST CHANGE THIS***
//This connects to the mysql DB
//***change username and password below***
$MZrandompic = @mysql_connect('localhost', 'username', 'password'); //***YOU MUST CHANGE THIS***
if (!$MZrandompic) {
echo( '<p>Unable to connect to the ' .
'database server at this time.</p>' );
exit();
}
//select photo DB
//***YOU MUST CHANGE THIS***
if (! @mysql_select_db('your data base name') ) {
die( '<p>Unable to locate the picture ' .
'database at this time.</p>' );
}
//This gets a random picture record from the database and
//the picture's location and displays it
$MZresult = @mysql_query("SELECT * FROM cpg132_pictures ORDER BY RAND() LIMIT 0,1");
if (!$MZresult) {
die('<p>Error performing query: ' . mysql_error() .
'</p>');
}
while ( $MZrow = mysql_fetch_array($MZresult) ) {
$albumid = $MZrow['aid']; //This gets the picture's associated album name
$pos = $MZrow['pid']; //This finds the picture's coppermine location
$filepath = $MZrow['filepath'];
$filename = $MZrow['filename'];
echo('<P ALIGN=center>');
echo('<a target = "_new" href="' . $copperminepath . '/displayimage.php?album=' . $albumid .
'&pos=-' . $pos . '">'); //make thumbnail clickable
echo('<IMG SRC="' . $copperminepath . '/albums/'); //append base dir structure
echo( $filepath .normal_. $filename .
'" alt=' . $MZrow['title'] . ' '. 'border=0 height=150>' . '</a> </br>'); //outputs path from /userspics
//echo('<FONT SIZE=2>');
echo($MZrow['title']);
}
//This displays the picture's album name and
//links it to the coppermine album
$MZalbumresult = @mysql_query("SELECT * FROM cpg132_albums WHERE aid = '$albumid'");
if (!$MZalbumresult) {
die('<p>Error performing query: ' . mysql_error() .
'</p>');
}
while ( $MZalbumname = mysql_fetch_array($MZalbumresult) ) {
echo('<FONT SIZE=1>');
echo('<P ALIGN=center>');
echo('<a href="' . $copperminepath .
'/thumbnails.php?album=' . $albumid . '">' .
$MZalbumname['title'] . '</a>' . '</p>');
}
if (! @mysql_select_db('your data base name') ) {
die( '<p>Unable to reload the main website ' .
'database at this time.</p>' );
}
//?>
</td>
</tr>
</table>
</br>
這樣應該就OK了