Как я могу получить количество записей в ответе ajax (ответ API WordPress, содержащийся в функции с именем myFetchPosts (страница)) и соответственно отобразить нумерацию страниц? (или даже ссылки на предыдущую и следующую страницу в порядке без номеров страниц в качестве альтернативы)
<!-- PAGINATION -->
<ul class="pagination text-center" role="navigation" aria-label="Pagination" data-page="6" data-total="16">
<li class="pagination-previous disabled">Previous<span class="show-for-sr">page</span></li>
<li class="current"><span class="show-for-sr">You're on page</span> 1</li>
<li><a href="#"class="page-link" data-page_number ="2" data-per-page="1" aria-label="Page 2">2</a></li>
<li><a href="#" class="page-link" data-page_number ="3" data-per-page="1" aria-label="Page 3">3</a></li>
<li><a href="#" class="page-link" data-page_number ="4" data-per-page="1" aria-label="Page 4">4</a></li>
<li class="ellipsis" aria-hidden="true"></li>
<li><a href="#" class="page-link" data-page_number ="12" data-per-page="1" aria-label="Page 12">12</a></li>
<li><a href="#" class="page-link" data-page_number ="13" data-per-page="1" aria-label="Page 13">13</a></li>
<li class="pagination-next"><a href="#" aria-label="Next page">Next <span class="show-for-sr">page</span></a></li>
</ul>
<script>
// Giving the selected page the class current and removes the class from previous selected page - not working only works once.
$(document).on('click', '.page-link', function(){
var page = $(this).data('page_number'); //take page number from pagination and use in function
var $listItems = $('.pagination li'); //find all li tags with this class
for (var i = 0; i < $listItems.length; i++) { // loop through li tags and when clicked change current class from existing to this clicked li
$listItems[i].addEventListener("click", function() {
var current = document.getElementsByClassName("current");
current[0].className = current[0].className.replace("current", "");
this.className += " current";
if (this.page !== 1) { //if the page is not one enable previous link
var previous = document.getElementsByClassName("pagination-previous disabled");
previous[0].className = previous[0].className.replace("disabled", "");
}
else {
}
});
}
myFetchPosts(page);
});
</script>