简体   繁体   English

切换按钮以显示和隐藏注释和WordPress注释表单

[英]Toggle button to show and hide both the comments and the WordPress comment form

I'm using WordPress Liveblog and a not-yet merged pull-request so will reference the code directly on the GitHub repo to hopefully explain my question better. 我正在使用WordPress Liveblog尚未合并的pull-request,因此将直接在GitHub存储库上引用该代码,以期更好地解释我的问题。 Please see here for a working example of the plugin code in action. 请参阅此处以了解实际使用的插件代码的示例。

The WordPress comment form is shown when I click on the Reply button . 当我单击“ 回复”按钮时,将显示WordPress注释表单。 Before clicking the button, the form is hidden from view. 在单击按钮之前,该表单从视图中隐藏。

The comments are shown when I click on the second reply button > Reply 当我单击第二个答复按钮>答复时,将显示评论

My aim is to replace both buttons with one single button called Toggle. 我的目标是用一个名为“切换”的单个按钮替换两个按钮。 When clicked, I'd like both the WordPress comment form AND the comments to be displayed. 单击后,我希望同时显示WordPress注释表单和注释。

So far I have done the following... 到目前为止,我已经完成了以下工作...

My Toggle button: 我的切换按钮:

<a class="toggle" href="#">Toggle</a>

My script (modified from here ): 我的脚本(从此处修改):

jQuery('a.toggle').click(function () {

    var openImgUrl = 'open.png',
        closeImgUrl = 'close.png';

    var $newsItem = jQuery(this).closest('.news-text'),
        $newsContent = $newsItem.find('.news-content'),
        isContentVisible = ($newsContent.is(':visible'));

    // slide up all shown news-items - but its expected that only one is visible at a time
    jQuery('.news-text').find('.news-content').slideUp(function () { 
        // on animation callback change the img
        jQuery('.news-text').find('.toggle > img').attr('src', openImgUrl);
    });

    if (!isContentVisible) { // if the new-item was hidden when clicked, then show it!
        $newsContent.slideDown(function () {
            // on animation callback change the img
            $newsItem.find('.toggle > img').attr('src', closeImgUrl);
        });
    }

    return false; // stop postback
});

Using my script and toggle button, when the Toggle button is clicked, comments are displayed under each entry. 使用我的脚本和切换按钮,单击“切换”按钮时,每个条目下方都会显示注释。 When the toggle button is clicked again, the comments are hidden. 再次单击切换按钮时,注释将隐藏。 However, this doesn't take the WordPress comment form into account. 但是,这并未考虑WordPress注释表单。

How can I get the WordPress comment form to display along with the comments when the Toggle button is clicked? 单击“切换”按钮时,如何使WordPress注释表单与注释一起显示?

Liveblog Glossary: Liveblog词汇表:

Entry: An entry is a top-level comment just like a standard 'comment' made in WordPress. 条目:条目是顶级注释,就像WordPress中的标准“注释”一样。

Comment: Comments can be made on entries. 注释:可以对条目进行注释。

I found comment_reply_link to be the answer! 我发现comment_reply_link是答案!

http://codex.wordpress.org/Function_Reference/comment_reply_link http://codex.wordpress.org/Function_Reference/comment_reply_link

Using this function to output the reply link enabled me to do what I needed. 使用此功能输出回复链接使我能够执行所需的操作。 I just had to change my selector in my script to use the comment reply button as the toggle and remove the original toggle button I had set up. 我只需要在脚本中更改选择器,即可将评论回复按钮用作切换按钮,并删除我设置的原始切换按钮。 For example: 例如:

jQuery('a.comment-reply-link').click(function () {

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM