2009-09-01 88 views
0

我做了如下的表格,但它不起作用,因爲它不會在帖子請求中發送帖子ID。如何製作自定義Wordpress評論表單?

<?php 
require('./wp-blog-header.php'); 
$post = get_post($_GET['p']); 
?> 

<form action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post" > 
<label>Name : </label><br/> 
<input name="author" id="author" type="text"/><br/> 
<label>Comment : </label><br/> 
<textarea name="comment" id="comment"></textarea><br/><br/> 
<input name="submit"type="submit" id="submit" value="Submit" /> 
<?php comment_id_fields(); ?> 
<?php do_action('comment_form', $post->ID); ?> 
</form> 

回答

1

WordPress將刪除任何無法識別的url參數。在url字符串中添加自定義參數的一種方法是使用Add_Query_Args()函數。

看看Add_Query_Args Function Reference

這應該解決您的問題。祝你好運。

1

只需稍微調整就可以使其工作。

<form action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post" id="commentform"> 

<p><input type="text" name="author" id="author" value="" size="22" tabindex="1" /> 
<label for="author"><small>*</small></label></p> 

<p><input type="text" name="email" id="email" value="" size="22" tabindex="2" /> 
<label for="email"><small>*</small></label></p> 

<p><textarea name="comment" id="comment" cols="48" rows="10" tabindex="4" onFocus="clearText(this)" onBlur="clearText(this)" ></textarea></p> 

<p><input name="submit" type="submit" id="submit" tabindex="5" value="Submit" /> 
<?php comment_id_fields(); ?> 

<?php do_action('comment_form', $post->ID); ?> 
</form> 

上面的代碼工程(對我來說)。基本上,你在表單上缺少一個id。 WP顯然使用該ID作爲驗證過程的一部分。

因此,要使其工作,請將id="commentform"添加到您的表單標籤中,並且它應該可以正常工作。