仅显示一定量的wordpress注释

时间:2018-04-26 06:15:26

标签: javascript php wordpress

我试图找出如何在wordpress中只显示前两个注释并隐藏休息并添加按钮,以便在需要时显示所有这些隐藏的消息。分页给我每页只有两个msg,这不是我想要的。有人可以告诉我这是如何实现这一目标或指向我的文章吗?

谢谢

2 个答案:

答案 0 :(得分:0)

这是一个应该完成工作的插件:https://wordpress.org/plugins/comment-load-more/

它有点过时(3年前)所以你应该检查代码是否仍然有效和兼容。

In"设置>评论加载"您应该能够设置首先显示的所需评论的数量。

确实,在本指南中 - http://www.wpbeginner.com/plugins/how-to-easily-lazy-load-comments-in-wordpress/ - 您将找到如何延迟加载所有评论。也许,通过一些修改,您也可以根据自己的需要进行调整。

干杯!

答案 1 :(得分:0)

// This function hide comments if is there more than two and add show more button      
 function fds_comments () {
        var commentWrap = document.getElementById('comment-list');
        var commentChilderns = commentWrap.children;
        for (var i = 2; i < commentChilderns.length; i++) {
            commentChilderns[i].style.display = "none";
        }
        commentWrap.innerHTML = commentWrap.innerHTML + "<button id='more-comments' onclick='fds_all_comments()'type='button' >Show all comments</button>";
    }

//This function reveal all comments (used on SHOW MORE btn)
    function fds_all_comments(){
        var commentWrap = document.getElementById('comment-list');
        var commentChilderns = commentWrap.children;
        for (var i = 0; i < commentChilderns.length; i++) {
            commentChilderns[i].style.display = "block";
        }
    }
// problem: comments hidden after submit
// solved: This additional code reveal comments after SUBMIT

window.onload = function() {
    var reloading = sessionStorage.getItem("reloading");
    if (reloading) {
        sessionStorage.removeItem("reloading");
        fds_all_comments();
    }
}

// function used on SUBMIT button
function fds_all_on_submit(){
    sessionStorage.setItem("reloading", "true");
    document.location.reload();
}
相关问题