如何讓wordpress所有留言都出現在一頁上,且有分頁功能:利用comment status外掛

瀏覽數:

最近又進入了留言的旺季,感冒沒有上網兩天,追留言就很辛苦(要登入後台才能用站長的資格看到所有留言),於是很認真的爬了一下文,看看有沒有好心人士釋出新的外掛,找到一個對岸露兜博客的版本,但是沒有頁碼,也沒有寫成外掛的樣子(好殘念!)

很不死心的又回到好久沒出現的CHweng那邊東張西望,突然看到自己在另一個plugin的頁面留言下面,有一位大好人叫「風痕影」留言說可以如何修改

修改方法

1
2
3
4
5
6
$tablecomments 與 $tableposts 已經在 WP 3 去掉了
請將程式碼中的 global $wpdb,$tablecomments,$tableposts; 改成 global $wpdb;
並將其餘程式中全部的

$tablecomments 改成 $wpdb->comments
$tableposts 改成 $wpdb->posts

於是乖乖的一個一個修改(其實是用replace),第一次失敗,出現fetal error,看了一下原來還有一個gloabl沒有改掉,心一橫,也把它改成global $wpdb,當噹噹!成功了。

但是輸出的畫面卻無法顯示作者和時間(嘆)好想哭啊!很努力的想了一想,應該是第二次改Global的時候不小心把$comment也拿掉的關係,小心的把它加回來!當噹噹!成功了!

(我有增加頁碼,原先是只有上面一個頁碼區可以連結,修改後上下都有)

  1. 下載rar檔 或是COPY下面comment-status-forWP3.php的程式碼
  2. 解壓縮,上傳comments-status-forWP3.php到你的plugin資料夾。
  3. 啟動這個plugin
  4. 進入wp-content/theme/你使用的theme/裡面,有一個page.php的檔案,複製一份。
  5. 把檔名改成comment-page.php
  6. 用記事本或其他網頁編輯器如PSPad,打開comment-page.php檔案,在裡面修改兩個地方的程式碼。
  7. 第一行的template name裡,改成template name:comment page
  8. 在get header();?> 之後,插入javascript轉址的語法。(記得將轉址的地方修改喔!)
  9. 儲存,上傳到你使用的theme folder裡。
  10. 在wordpress後台新建一個page,並使用剛剛這個comment page模板(右側有選擇的地方)
  11. 把解壓縮出來的myRcomments.php,上傳到部落格安裝的最頂層的資料夾。例如/blog/下面。
  12. 大功告成!(myRcomments.php可能會因你用的theme 的CSS structure有些不同,請自己調整囉!)

comment-status-forWP3.php 用外掛分頁顯示wordpress裡面所有留言:原創為CHweng,這邊是依據風痕影的建議將他修改成WP3可以用的版本

English notice: copy the code and save as comment-status-forWP3.php, then upload to your plugin folder. Active it!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
< ?php /* Plugin Name: Comments Status for WP3 Plugin URI: http://www.chweng.idv.tw/blog/wordpress/comments-status/ Description: Counts the total number of comments and layout a comments list in a clean form. Version: 0.2 Author: C.H.Weng Author URI: http://www.chweng.idv.tw/ */ $numsperpage = 40; //設定每頁顯示的數量 if (isset($_GET['page'])) { $curpage=$_GET['page']; } else { $curpage=1; } function comments_count() { global $wpdb; $comnum=$wpdb->get_var("SELECT COUNT(ID) FROM $wpdb->posts,$wpdb->comments WHERE $wpdb->posts.ID=$wpdb->comments.comment_post_ID AND post_status IN ('publish','static') AND $wpdb->comments.comment_approved='1' AND $wpdb->comments.comment_type=''");
return $comnum;
}

function trackbacks_count() {
global $wpdb;
$comnum=$wpdb->get_var("SELECT COUNT(ID) FROM $wpdb->posts,$wpdb->comments WHERE $wpdb->posts.ID=$wpdb->comments.comment_post_ID AND post_status IN ('publish','static') AND $wpdb->comments.comment_approved='1' AND $wpdb->comments.comment_type IN ('trackback','pingback')");
return $comnum;
}

function comments_archives($type = 'comment') {
global $wpdb,$comment;
global $numsperpage,$curpage;
if ($type=='trackback') {
$comnum=trackbacks_count();
} else {
$comnum=comments_count();
}
if (($comnum/$numsperpage)>intval($comnum/$numsperpage)) {
$maxpage=intval($comnum/$numsperpage)+1;
} else {
$maxpage=intval($comnum/$numsperpage);
}
if ($curpage<1 || $curpage!=intval($curpage) || $maxpage< $curpage) { header('Location: '.$_SERVER['PHP_SELF']); } $offset=($curpage-1)*$numsperpage; $query="SELECT ID,comment_ID,comment_author,comment_author_url,comment_date,comment_content,post_title FROM $wpdb->posts,$wpdb->comments WHERE $wpdb->posts.ID=$wpdb->comments.comment_post_ID AND post_status IN ('publish','static') AND $wpdb->comments.comment_approved='1'";
if ($type=='trackback') {
$query.=" AND $wpdb->comments.comment_type IN ('trackback','pingback')";
} else {
$query.=" AND $wpdb->comments.comment_type=''";
}
$query.=" ORDER BY comment_ID DESC LIMIT $offset,$numsperpage";
$comments=$wpdb->get_results($query);
echo '

';
if ($maxpage>1) {
if ($curpage>6) {
echo '[第一頁 First page] …';
}
for ($i=($curpage-5); $i< =($curpage+5); $i++) { if ($i>=1 && $i< =$maxpage) { echo ' '; if ($i==$curpage) { echo $i; } else { echo '[$i]"; } echo ' '; } } if ($maxpage>($curpage+5)) {
echo '… [最末頁 Last page] ";
}
}
echo "
共有 $comnum 筆留言;目前顯示第 $curpage 頁的留言;共 $maxpage 頁。

\r\n";
echo "
You have $comnum comments;Now you are in page $curpage of $maxpage
\r\n";
foreach ($comments as $comment) {
$post_title=htmlspecialchars(stripslashes($comment->post_title));
if($post_title!=$cache_post_title) {
echo '
$post_title

\r\n";
}
echo '
'.get_comment_author_link().' at '.get_comment_date().' '.get_comment_time().'
'.apply_filters('comment_text',apply_filters('get_comment_text',$comment->comment_content)).'

';
$cache_post_title=$post_title;
}
echo '

';
echo "
共有 $comnum 筆留言;目前顯示第 $curpage 頁的留言;共 $maxpage 頁。
\r\n";
echo "
You have $comnum comments;Now you are in page $curpage of $maxpage
\r\n";
if ($maxpage>1) {
if ($curpage>6) {
echo '

[第一頁First page] …';
}
for ($i=($curpage-5); $i< =($curpage+5); $i++) { if ($i>=1 && $i< =$maxpage) { echo ' '; if ($i==$curpage) { echo $i; } else { echo '[$i]"; } echo ' '; } } if ($maxpage>($curpage+5)) {
echo '… [最末頁Last page]

";
}
}
}
?>

comment-page.php 先修改template name,接著在get header之後加入javascript轉址

English notice: Copy page.php from your current theme folder. Rename it as the comment-page.php. Use notepad to figure the code as below. (1. change the template name, 2. add a redirect code). Upload it back to your theme folder. Then, go back to post a new page (name whatever your want). use this template and publish it. (you might change the menu setting to let user see this page)

1
2
3
4
< ?php /*Template Name: comment page*/ get_header(); >

<script type="text/javascript">// < ![CDATA[
// < ![CDATA[ var URL = "http:/你的網址/blog/myRcomments.php" var speed = 500 function reload() { location = URL } setTimeout("reload()", speed); // ]]></script>

顯示頁myRcomments.php,原外掛的寫法不需另創顯示頁,但頁碼有問題,需另創顯示頁並放在blog/下面

English note: Copy the code and save as myRcomments.php. Upload it under your blog link. (somewhere http://domain/blog/) You may need to modify the css control for fitting your theme setting.

1
2
3
4
5
6
&lt; ?php require(dirname(__FILE__).'/wp-blog-header.php'); ?&gt;
&lt; ?php get_header(); ?&gt;
本站所有留言All comments
&lt; ?php comments_archives('comment'); ?&gt;
&lt; ?php get_sidebar(); ?&gt;
&lt; ?php get_footer(); ?&gt;

結果:
MFAstudy本站所有留言

分享到你的社群
  •  
  •  
  •  
  •  
  •  

4 Comments

  1. Pingback: Arras Theme Review and Wordpress plug in list | MFA!study

  2. 你好,我很想實現這樣的顯示所有評論功能,但試了你的方法,無法奏效,我的博客平臺是wordpress 3.2.1,請問能解決嗎?謝謝。

    PS:請問博主可以把文章中提到的程序文件打包提供下載嗎?

    lelouch

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *