В WordPress на странице редактирования поста имеется блок "Комментарии", который отображает не все комментарии, а только первые 10, и надо каждый раз кликать по кнопке "Показать ещё комментарии".
В коде ссылка выглядит так.
<p class="hide-if-no-js" id="show-comments"><a href="#commentstatusdiv" onclick="commentsBox.load(<?php echo $total; ?>);return false;"><?php _e( 'Show comments' ); ?></a>
И если комментариев много, то приходится каждый раз кликать по этой ссылке, чтобы они вcе отобразились и в конце отобразилась надпись "Больше комментариев не найдено."
<p class="hide-if-no-js" id="show-comments" style="display: none;">Больше комментариев не найдено.</p>
на style="display: none; обращать внимание не стоит, в CSS я добавил
.inside #show-comments {
display: block !important;
}
Как можно за счёт одного нажатия отображать все комментарии, типа, наверное, зациклить клик, пока не появится надпись "Больше комментариев не найдено." Как это можно сделать?
Вот кусок кода из
файла WordPress, где предположительно всё и происходит.
/**
* Fetch comments using Ajax and display them in the box.
*
* @memberof commentsBox
*
* @param {number} total Total number of comments for this post.
* @param {number} num Optional. Number of comments to fetch, defaults to 20.
* @return {boolean} Always returns false.
*/
get : function(total, num) {
var st = this.st, data;
if ( ! num )
num = 20;
this.st += num;
this.total = total;
$( '#commentsdiv .spinner' ).addClass( 'is-active' );
data = {
'action' : 'get-comments',
'mode' : 'single',
'_ajax_nonce' : $('#add_comment_nonce').val(),
'p' : $('#post_ID').val(),
'start' : st,
'number' : num
};
$.post(
ajaxurl,
data,
function(r) {
r = wpAjax.parseAjaxResponse(r);
$('#commentsdiv .widefat').show();
$( '#commentsdiv .spinner' ).removeClass( 'is-active' );
if ( 'object' == typeof r && r.responses[0] ) {
$('#the-comment-list').append( r.responses[0].data );
theList = theExtraList = null;
$( 'a[className*=\':\']' ).off();
// If the offset is over the total number of comments we cannot fetch any more, so hide the button.
if ( commentsBox.st > commentsBox.total )
$('#show-comments').hide();
else
$('#show-comments').show().children('a').text( __( 'Show more comments' ) );
return;
} else if ( 1 == r ) {
$('#show-comments').text( __( 'No more comments found.' ) );
return;
}
$('#the-comment-list').append('<tr><td colspan="2">'+wpAjax.broken+'</td></tr>');
}
);
return false;
},