我有一个插件可以让Facebook评论WordPress。用户已请求一项功能,该功能将在启用Facebook评论的帖子上隐藏默认的WordPress评论表单。
如何动态隐藏WP评论表?我知道我可以从comment_form();
模板中注释掉comments.php
,但我希望能够通过点击按钮隐藏/取消隐藏它。
是否与comments_template
过滤器有关?
答案 0 :(得分:5)
将表单包装在div中并使用这个简单的jquery来显示/隐藏div。
<div class="comments">
<?php comment_form(); ?>
</div>
<a class="comment_switch">Show / Hide Comments</a>
.hidden{display:none;}
$("comment_switch").click(function () {
$("comments").toggleClass("hidden")");
});
答案 1 :(得分:0)
我也有这种需要出现。我已经用适当的消息替换了评论表。这是挂钩代码,您可以根据需要更改条件。
/**
* Restrict WordPress comment posting to Admin, Authors and HW+ active users
*/
function fun_comment_form_defaults( $defaults ) {
if ( comments_open() && is_user_logged_in() && ( is_admin() || current_user_can( 'edit_others_posts', get_the_ID() ) || wc_memberships_is_user_active_member( get_current_user_id(), 'hw' ) ) ) {
return $defaults;
} else {
$defaults['comment_field'] = wp_kses_post( sprintf( '<p>You should require an active <a href="%s">HW+ membership</a> to post a comment.</p>', esc_url( get_site_url() . '/membership/' ) ) );
$defaults['submit_button'] = '';
$defaults['submit_field'] = '';
$defaults['fields'] = '';
return $defaults;
}
}
add_filter( 'comment_form_defaults', 'fun_comment_form_defaults' );