#1 2009-03-16 09:35:43
PunBB 首頁顯示最新文章
一直想在首頁列出最近討論的文章,方便網友快速點選瀏覽,所以花了一點時間蒐集資料。
終於找到 PunBB Resource 文章及參考原本的 viewforum.php 內容,修改出另一獨立程式碼=> recent_post.php
底下說明如何修改:
首先在 /punbb/include/user 新增 recent_post.php
內容:
<?php
define('PUN_ROOT', './');
require PUN_ROOT.'lang/'.$pun_user['language'].'/forum.php';
global $lang_common, $db, $pun_config, $db_prefix;
$order_by = 't.last_post';
$forum_sql = '';
$show=5;
?>
<div id="vf" class="blocktable">
<h2 class="block2"><span>最新文章</span></h2>
<div class="box">
<div class="inbox">
<table cellspacing="0">
<thead>
<tr>
<th class="tcl" scope="col"><?php echo $lang_common['Topic'] ?></th>
<th class="tc2" scope="col"><?php echo $lang_common['Replies'] ?></th>
<th class="tc3" scope="col"><?php echo $lang_forum['Views'] ?></th>
<th class="tcr" scope="col"><?php echo $lang_common['Last post'] ?></th>
</tr>
</thead>
<tbody>
<?php
// Fetch $show topics
$result = $db->query('SELECT t.id, t.subject, t.poster, t.posted, t.last_post, t.last_post_id, t.last_poster, t.num_views, t.num_replies, t.closed, t.sticky, t.moved_to FROM '.$db->prefix.'topics AS t INNER JOIN '.$db->prefix.'forums AS f ON f.id=t.forum_id LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=f.id AND fp.group_id=3) WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND t.moved_to IS NULL'.$forum_sql.' ORDER BY '.$order_by.' DESC LIMIT '.$show) or error('Unable to fetch topic list', __FILE__, __LINE__, $db->error());
if ($db->num_rows($result))
{
while ($cur_topic = $db->fetch_assoc($result))
{
$icon_text = $lang_common['Normal icon'];
$item_status = '';
$icon_type = 'icon';
if ($cur_topic['moved_to'] == null)
$last_post = '<a href="viewtopic.php?pid='.$cur_topic['last_post_id'].'#p'.$cur_topic['last_post_id'].'">'.format_time($cur_topic['last_post']).'</a> <span>'.$lang_common['by'].' '.pun_htmlspecialchars($cur_topic['last_poster']).'</span>';
else
$last_post = ' ';
if ($pun_config['o_censoring'] == '1')
$cur_topic['subject'] = censor_words($cur_topic['subject']);
if ($cur_topic['moved_to'] != 0)
$subject = $lang_forum['Moved'].': <a href="viewtopic.php?id='.$cur_topic['moved_to'].'">'.pun_htmlspecialchars($cur_topic['subject']).'</a> <span class="byuser">'.$lang_common['by'].' '.pun_htmlspecialchars($cur_topic['poster']).'</span>';
else if ($cur_topic['closed'] == '0')
$subject = '<a href="viewtopic.php?id='.$cur_topic['id'].'">'.pun_htmlspecialchars($cur_topic['subject']).'</a> <span class="byuser">'.$lang_common['by'].' '.pun_htmlspecialchars($cur_topic['poster']).'</span>';
else
{
$subject = '<a href="viewtopic.php?id='.$cur_topic['id'].'">'.pun_htmlspecialchars($cur_topic['subject']).'</a> <span class="byuser">'.$lang_common['by'].' '.pun_htmlspecialchars($cur_topic['poster']).'</span>';
$icon_text = $lang_common['Closed icon'];
$item_status = 'iclosed';
}
if (!$pun_user['is_guest'] && $cur_topic['last_post'] > $pun_user['last_visit'] && $cur_topic['moved_to'] == null)
{
$icon_text .= ' '.$lang_common['New icon'];
$item_status .= ' inew';
$icon_type = 'icon inew';
$subject = '<strong>'.$subject.'</strong>';
$subject_new_posts = '<span class="newtext">[ <a href="viewtopic.php?id='.$cur_topic['id'].'&action=new" title="'.$lang_common['New posts info'].'">'.$lang_common['New posts'].'</a> ]</span>';
}
else
$subject_new_posts = null;
// Should we display the dot or not? :)
if (!$pun_user['is_guest'] && $pun_config['o_show_dot'] == '1')
{
if ($cur_topic['has_posted'] == $pun_user['id'])
$subject = '<strong>·</strong> '.$subject;
else
$subject = ' '.$subject;
}
if ($cur_topic['sticky'] == '1')
{
$subject = '<span class="stickytext">'.$lang_forum['Sticky'].': </span>'.$subject;
$item_status .= ' isticky';
$icon_text .= ' '.$lang_forum['Sticky'];
}
$num_pages_topic = ceil(($cur_topic['num_replies'] + 1) / $pun_user['disp_posts']);
if ($num_pages_topic > 1)
$subject_multipage = '[ '.paginate($num_pages_topic, -1, 'viewtopic.php?id='.$cur_topic['id']).' ]';
else
$subject_multipage = null;
// Should we show the "New posts" and/or the multipage links?
if (!empty($subject_new_posts) || !empty($subject_multipage))
{
$subject .= ' '.(!empty($subject_new_posts) ? $subject_new_posts : '');
$subject .= !empty($subject_multipage) ? ' '.$subject_multipage : '';
}
?>
<tr<?php if ($item_status != '') echo ' class="'.trim($item_status).'"'; ?>>
<td class="tcl">
<div class="intd">
<div class="<?php echo $icon_type ?>"><div class="nosize"><?php echo trim($icon_text) ?></div></div>
<div class="tclcon">
<?php echo $subject."\n" ?>
</div>
</div>
</td>
<td class="tc2"><?php echo ($cur_topic['moved_to'] == null) ? $cur_topic['num_replies'] : ' ' ?></td>
<td class="tc3"><?php echo ($cur_topic['moved_to'] == null) ? $cur_topic['num_views'] : ' ' ?></td>
<td class="tcr"><?php echo $last_post ?></td>
</tr>
<?php
}
}
else
{
?>
<tr>
<td class="tcl" colspan="4"><?php echo $lang_forum['Empty forum'] ?></td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
</div>
</div>
編輯 index.php
在 require PUN_ROOT.'header.php'; 下面一行
加入 require PUN_ROOT.'include/user/recent_post.php';
展開首頁即可測試,完工。
備註:$show 為指定顯示篇數
參考: http://www.punres.org/viewtopic.php?pid=24228#p24228
技術問題請於論壇上集眾人之力公開討論,感恩

離線
#2 2010-08-08 15:02:33
Re: PunBB 首頁顯示最新文章
如题
在http://www.ezdiy.org/forum/viewtopic.php?id=377看到版大的文章 感觉不错
按此操作以后 在论坛首页显示文章名没问题 但是上面分区标题是乱码。这才想起是我的论坛选择的简体中文
只是实在对php不熟悉 只好把最近文章更改为英文了
请教如何更改这段代码 才能正常显示简体中文?谢谢
不过已经很开心了 呵呵
<?php
define('PUN_ROOT', './');
require PUN_ROOT.'lang/'.$pun_user['language'].'/forum.php';
global $lang_common, $db, $pun_config, $db_prefix;
$order_by = 't.last_post';
$forum_sql = '';
$show=5;
?>
<div id="vf" class="blocktable">
<h2 class="block2"><span>最近文章</span></h2>
<div class="box">
<div class="inbox">
<table cellspacing="0">
<thead>最後修改: lyyzh78 (2010-08-08 15:08:48)
我的简陋网站 木有了
離線
#3 2010-08-08 17:08:18
Re: PunBB 首頁顯示最新文章
lyyzh78 提到:
如题
在http://www.ezdiy.org/forum/viewtopic.php?id=377看到版大的文章 感觉不错
按此操作以后 在论坛首页显示文章名没问题 但是上面分区标题是乱码。这才想起是我的论坛选择的简体中文
只是实在对php不熟悉 只好把最近文章更改为英文了
请教如何更改这段代码 才能正常显示简体中文?谢谢
不过已经很开心了 呵呵<?php define('PUN_ROOT', './'); require PUN_ROOT.'lang/'.$pun_user['language'].'/forum.php'; global $lang_common, $db, $pun_config, $db_prefix; $order_by = 't.last_post'; $forum_sql = ''; $show=5; ?> <div id="vf" class="blocktable"> <h2 class="block2"><span>最近文章</span></h2> <div class="box"> <div class="inbox"> <table cellspacing="0"> <thead>
我猜您應該是把 recent_post.php 存成 GB 編碼格式所致,您要把檔案存成 UTF-8 格式(檔首無BOM)即可。
技術問題請於論壇上集眾人之力公開討論,感恩

離線
相關討論主題
| 主題 | 回覆 | 點閱 | 最後發表 |
|---|---|---|---|
|
[PunBB]麥擱CODE啊,一起來美化您的 code tag 作者 Aven
|
0 | 10589 | 2009-10-13 22:36:10 作者 Aven |
|
sqlite/punbb 安裝失敗 作者 ecolitely
|
9 | 37769 | 2009-06-29 21:06:16 作者 Aven |
|
PunBB 推出 1.3 Beta 版 作者 Aven
|
0 | 10051 | 2008-01-30 14:37:38 作者 Aven |
|
置頂 |
0 | 31356 | 2007-12-18 22:48:28 作者 Aven |
版大正解啊 已经修改好了 对编码不了解导致这种情况的发生 汗。 把文件ftp下来 用文本编辑打开 另存为UTF-8 再上传解决了。谢谢




