为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

网摘: Yahoo Baidu Google Bolaa 365Key Yesky Wozhai POCO ViVi YouNote Hexun Del.icio.us Yeeyoo igooi I2Key Cn3 Bytemen Furl Blinklist Blogmarks Technorati 分享到饭否

« 上一篇: 让WordPress上传的图片自动支持Light... | 下一篇:Don McLean:Vincent »

引用: 点击获得Trackback地址,Encode: UTF-8 点击获得Trackback地址,Encode: GB2312 or GBK 点击获得Trackback地址,Encode: BIG5
» 我要发表评论 你的参与是我最大的动力!    访客评论: (6条记录)
  1. 1楼 pcexp 引用回复该评论
    可以的话麻烦大哥把
    comments_book.php和comment-template.php
    都发一份给我好吗?手动修改太累了
    pc_exp@163.com
    谢谢
  2. 2楼 pcexp 引用回复该评论
    留言本OK了~多谢多谢
  3. 3楼 Kevin 引用回复该评论
    呵呵,不用客气!
  4. 4楼 JACKO 引用回复该评论
    首页当然是新建一个Page,命名为“留言本本”,地址为:http://www.bluefeel.com/guest-book/,在相应的位置做好链接。

    我新建了一个Page,并命名为“留言本本”,请问在哪里设置成为guest-book/这个目录呢?
  5. 5楼 JACKO 引用回复该评论
    Leave a Reply
  6. 6楼 Kevin 引用回复该评论
    To JACKO:不好意思,忘了说明一下,我的WordPress使用了rewrite!
 
发表评论:( 来了就留个脚印吧!你的参与是我最大的动力!)