我建立了一个Wordpress网站,可以在页面上发表评论,我将它们用作评论,我想做的是让某人能够在页面上发表评论,而不必在该页面上。
http://universitycompare.com/university-guide/anglia-ruskin-university/
在右上方的链接上,有一个链接说
have your say about a university, 最好有一个HTML表单,然后有一个包含所有子页面的下拉框
university-guide; 所有大学都存放在这里,然后我可以发表我的评论。php文件转换为此。
因此,我的HTML表单出现,当从下拉框中选择一个页面时,注释将分配给该页面。
有什么帮助或指导吗?
托肖的新问题:
下面是你调整的插件,适合我的网站,你可以看到我添加了选择选项yearSelect 并且需要在注释出现时显示此内容。我该怎么做呢?-你能提供帮助吗?
<?php
/* Plugin Name: haveyoursay */
/**
* Call the form in your template with:
* do_action( \'wpse_67527_comment_form\' );
*/
add_action( \'wpse_67527_comment_form\', \'wpse_67527_comment_form\' );
/**
* Create a review form.
*
* @return void
*/
function wpse_67527_comment_form()
{
$select_id = \'page_select\';
$url = \'http\' . ( is_ssl() ? \'s\' : \'\' ) . \'://\' . $_SERVER[\'HTTP_HOST\'] . $_SERVER[\'REQUEST_URI\'];
$url = esc_url( $url );
?>
<form action="<?php echo site_url( \'/wp-comments-post.php\' ); ?>" method="post">
<h3>Leave us your student perspective <img src="/wp-content/themes/blue-and-grey/images/hmepage-tri.png"></h3>
<p>
<label for="author"><?php _e( \'Name\' ); ?></label>
<input id="author" name="author" type="text" size="40" />
</p>
<p>
<label for="email"><?php _e( \'Email\' ); ?></label>
<input id="email" name="email" type="text" size="40" />
</p>
<p>
<label for="<?php echo $select_id; ?>">
<div class="clear"></div>
Pick a university from the list:
</label>
<?php
// Ordered by page name automatically
wp_dropdown_pages(
array (
\'name\' => \'comment_post_ID\',
\'id\' => $select_id,
\'child_of\' => 2,
)
);
?>
</p>
<div class="clear"></div>
<p style="margin:10px 0px 0px 0px;">Please select your year of study:
<select name="yearSelect">
<option value="1st">First Year</option>
<option value="2nd">Second Year</option>
<option value="2nd">Third Year</option>
</select>
</p>
<br />
<p>
<textarea name="comment" cols="45" rows="8"></textarea>
</p>
<p>
<?php
wp_nonce_field( \'unfiltered-html-comment_\' . get_the_ID(), \'_wp_unfiltered_html_comment_disabled\', FALSE );
?>
<input type="hidden" name="redirect_to" value="<?php echo $url; ?>" />
<input type="submit" style="margin:15px 0px 0px 0px; padding:4px 10px;" />
</p>
</form>
<?php
}
add_filter( \'comment_post_redirect\', \'wpse_67527_redirect\' );
/**
* Strip \'#comment-number\' from redirect url.
*
* @param string $url
* @return string
*/
function wpse_67527_redirect( $url )
{
$parts = explode( \'#\', $url );
return $parts[0];
}
?>
最合适的回答,由SO网友:fuxia 整理而成
您必须设置$_POST[\'comment_post_ID\']
至页面的帖子id:
<input type=\'hidden\' name=\'comment_post_ID\' value=\'10\' />
然后设置
action
表单元素的
/wp-comments-post.php
, 滤器
\'comment_post_redirect\'
并将访问者发送回撰写评论/评论的页面。
以下是一个以插件形式编写的示例:
<?php
/* Plugin Name: Comment on different page */
/**
* Call the form in your template with:
* do_action( \'wpse_67527_comment_form\' );
*/
add_action( \'wpse_67527_comment_form\', \'wpse_67527_comment_form\' );
/**
* Create a review form.
*
* @return void
*/
function wpse_67527_comment_form()
{
$select_id = \'page_select\';
$url = \'http\' . ( is_ssl() ? \'s\' : \'\' ) . \'://\' . $_SERVER[\'HTTP_HOST\'] . $_SERVER[\'REQUEST_URI\'];
$url = esc_url( $url );
?>
<form action="<?php echo site_url( \'/wp-comments-post.php\' ); ?>" method="post">
<p>
<label for="<?php echo $select_id; ?>">
Choose a page
</label>
<?php
// Ordered by page name automatically
wp_dropdown_pages(
array (
\'name\' => \'comment_post_ID\',
\'id\' => $select_id,
\'child_of\' => 2,
)
);
?>
</p>
<p>
<textarea name="comment" cols="45" rows="8"></textarea>
</p>
<p>
<label for="author"><?php _e( \'Name\' ); ?></label>
<input id="author" name="author" type="text" size="30" />
</p>
<p>
<label for="email"><?php _e( \'Email\' ); ?></label>
<input id="email" name="email" type="text" size="30" />
</p>
<p>
<?php
wp_nonce_field( \'unfiltered-html-comment_\' . get_the_ID(), \'_wp_unfiltered_html_comment_disabled\', FALSE );
?>
<input type="hidden" name="redirect_to" value="<?php echo $url; ?>" />
<input type="submit" />
</p>
</form>
<?php
}
add_filter( \'comment_post_redirect\', \'wpse_67527_redirect\' );
/**
* Strip \'#comment-number\' from redirect url.
*
* @param string $url
* @return string
*/
function wpse_67527_redirect( $url )
{
$parts = explode( \'#\', $url );
return $parts[0];
}
我将行动称为:
is_front_page() and do_action( \'wpse_67527_comment_form\' );
…在
index.php
并获得一个简单的评论表单,将其内容发送到另一个页面。:)