私は、Wordpress で非常にうまく機能するこの素晴らしい小さなコードを持っています。これは基本的にカスタム ループに [さらに読み込む] ボタンを追加し、クリックするとその下に次の多くの投稿が追加されます。
私が抱えている問題は、以下のスニペットから取得したこのコード行にあります。error: function() { jQuery('button.load-more').attr('disabled', 'disabled').text('No More Posts') } // Disable the button and change its contents when there are no more posts
基本的に、投稿がなくなると、ボタンは指示どおりに無効になりません。誰かが私を修正するのを手伝ってもらえますか? 完全なJSは次のとおりです。
var page = 1;
loadMore = function () {
page++ //Increments the page number in the request
$.ajax({
url: './page/' + page,
beforeSend: function () {
$('#wait').show().parent().find('button.load-more').hide();
},
complete: function () {
$('#wait').hide().parent().find('button.load-more').show();
},
success: function (data) {
var $data = $(data).find('article');
// Replace div#the-posts with the name of your post container
jQuery('#posts .inner').append($data);
},
error: function () {
jQuery('button.load-more').attr('disabled', 'disabled').text('No More Posts')
} // Disable the button and change its contents when there arew no more posts
}); // End Ajax
}; // End loadMore
jQuery('button.load-more').on('click', loadMore);