First, you have to "alter" your database to add a new field to the b2posts table. Login to your CPanel and then phpMyAdmin; click on "b2posts" table and then go into the SQL section. In this section, run the following: ALTER TABLE b2posts ADD post_closecomment INT(1) DEFAULT 0 NOT NULL; --- In b2functions.php file, locate get_postdata and get_postdata2 fuunctions. Then add in the following lines in each function respectively: 'CloseComment' => $mysql->post_closecomment and 'CloseComment' => $row->post_closecomment --- In b2edit.form.php file, locate: Add the following next to it: tabindex="8" id="closecomment" />
If this does not work for some reason, use the following instead: post_closecomment; if ($rc == 1) { echo " checked"; } } ?> tabindex="9" id="closecomment" />
Which ever you use, you might want to change the tabindex value. --- In b2template.functions.php file, replace the comments_link function with the following: function comments_link($file='') { global $id, $pagenow, $postdata; global $querystring_start, $querystring_equal, $querystring_separator; if ($file == '') $file = $pagenow; if ($file == '/') $file = ''; if ($postdata["CloseComment"] == 0) { echo $file.$querystring_start.'p'.$querystring_equal.$id.$querystring_separator.'c'.$querystring_equal.'1#comments'; } else { echo 'comments closed'; } } If you use the popup comment, replace the comments_popup_link function with the following: function comments_popup_link($zero='no comment', $one='1 comment', $more='% comments', $CSSclass='') { global $id, $b2commentspopupfile, $b2commentsjavascript, $postdata; global $querystring_start, $querystring_equal, $querystring_separator; if ($postdata["CloseComment"] == 0) { echo ''; comments_number($zero, $one, $more); echo ''; } else { echo 'comments closed'; } } And if you use trackback, do the same: function trackback_link($file='') { global $id, $pagenow, $postdata; global $querystring_start, $querystring_equal, $querystring_separator; if ($file == '') $file = $pagenow; if ($file == '/') $file = ''; if ($postdata["CloseComment"] == 0) { echo $file.$querystring_start.'p'.$querystring_equal.$id.$querystring_separator.'tb'.$querystring_equal.'1'; } else { echo 'trackbacks closed'; } } function trackback_popup_link($zero='no trackback', $one='1 trackback', $more='% trackbacks', $CSSclass='') { global $id, $b2trackbackpopupfile, $b2commentsjavascript, $postdata; global $querystring_start, $querystring_equal, $querystring_separator; if ($postdata["CloseComment"] == 0) { echo ''; trackback_number($zero, $one, $more); echo ''; } else { echo 'trackbacks closed'; } } --- In b2edit.php file, add in the following line under both "post" and "editpost" sections: $post_closecomment = intval($HTTP_POST_VARS["post_closecomment"]); Then edit the INSERT statement under "post" as: $query = "INSERT INTO $tableposts (ID, post_author, post_date, post_content, post_title, post_category, post_closecomment) VALUES ('0','$user_ID','$now','$content','".$post_title."','".$post_category."','".$post_closecomment."')"; Also edit the UPDATE statement under "editpost" as: $query = "UPDATE $tableposts post_closecomment=\"$post_closecomment\", post_mood=\"$post_mood\", post_content=\"$content\", post_title=\"$post_title\", post_category=\"$post_category\"".$datemodif." WHERE ID=$post_ID"; These lines may look different depending which hack(s) you have installed. --- If you use inline comments, you don't have to edit the b2comments.php file since it can be loaded by itself, but you do need to restrict the inclusion of comments within your index... like: However, if you use the popup comments, open up b2commentspopup.php file and locate:
:: comments
Add the following right above that line: "; } else { ?> Then add the following after the comments form: You can do the same for b2pingbackpopup.php and b2trackbackpopup.php files if you are familiar with b2. --- Now if you want to disable trackbacks for posts with closed comments, locate the following line in trackback.php file: dbconnect(); Add the following next to it: $querytb = mysql_query("SELECT post_closecomment FROM $tableposts WHERE ID=$tb_id"); $tbrow = mysql_fetch_object($querytb); $tb_status = $tbrow->post_closecomment; if ($tb_status == 1) { trackback_response(1, 'Sorry, trackbacks are closed for this post.'); } For pingback, locate the following lines under pingback_ping function in xmlrpc.php file: } else { $post_ID = -1; } Add the following next to it: $querypb = mysql_query("SELECT post_closecomment FROM $tableposts WHERE ID=$post_ID"); $pbrow = mysql_fetch_object($querypb); $pb_status = $pbrow->post_closecomment; if ($pb_status == 1) { return new xmlrpcresp(new xmlrpcval(('Sorry, trackbacks are closed for this post.')); } Done! :)