为WordPress增加留言本本
该日志由
Kevin
发表于 2007, June 3, 9:46 AM
今天心血来潮,想为WordPress增加一个留言本本,虽然WordPress的评论功能已经很不错了,但是要做成留言簿的形式的话比较好的方法是利用WordPress的Page功能,另外,要利用Page功能做成留言本,还需要在细节上作一些修改,具体修改如下(以我自己的留言本本为例,其实细节礼视个人习惯而异):
首页当然是新建一个Page,命名为“留言本本”,地址为:
http://www.bluefeel.com/guest-book/,在相应的位置做好链接。
打开模板文件page.php,在适当的位置加下如下代码:
把模板文件comments.php复制后命名为comments_book.php,然后打开作一些相应的细节修改,比如把“评论”等字眼改为“留言”,等等,自己喜欢就行!
打开wp-includes\comment-template.php,查找:
function comments_popup_script($width=400, $height=400, $file='')
在上面增加以下代码:
function comments_book_template( $file = '/comments_book.php' ) {
global $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_ID, $user_identity;
if ( ! (is_single() || is_page() || $withcomments) )
return;
$req = get_option('require_name_email');
$commenter = wp_get_current_commenter();
extract($commenter);
// TODO: Use API instead of SELECTs.
if ( empty($comment_author) ) {
$comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_post_ID = '$post->ID' AND comment_approved = '1' ORDER BY comment_date DESC");
} else {
$author_db = $wpdb->escape($comment_author);
$email_db = $wpdb->escape($comment_author_email);
$comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_post_ID = '$post->ID' AND ( comment_approved = '1' OR ( comment_author = '$author_db' AND comment_author_email = '$email_db' AND comment_approved = '0' ) ) ORDER BY comment_date DESC");
}
$comments = apply_filters( 'comments_array', $comments, $post->ID );
define('COMMENTS_BOOK_TEMPLATE', true);
$include = apply_filters('comments_book_template', TEMPLATEPATH . $file );
if ( file_exists( $include ) )
require( $include );
else
require( ABSPATH . 'wp-content/themes/default/comments_book.php');
}
上传更新文件,OK,搞定了!
Update:有人需要comments_book.php和comment-template.php这两个文件,那就提供一下:
点击下载comments_book.php和comment-template.php
« 上一篇: 让WordPress上传的图片自动支持Light... | 下一篇:Don McLean:Vincent »
» 我要发表评论 你的参与是我最大的动力! 访客评论:
(6条记录)
发表评论:( 来了就留个脚印吧!你的参与是我最大的动力!)
comments_book.php和comment-template.php
都发一份给我好吗?手动修改太累了
pc_exp@163.com
谢谢
我新建了一个Page,并命名为“留言本本”,请问在哪里设置成为guest-book/这个目录呢?