jQuery(document).ready(function($) { $('div[class^="tlr-container-"]').each(function() { var container = $(this); var listId = container.data('list-id'); container.on('click', '.tlr-pagination-' + listId + ' a', function(e) { e.preventDefault(); var link = $(this); var page = 1; // استخراج رقم الصفحة من الرابط var href = link.attr('href'); var match = href.match(/[?&]paged=(\d+)/); if (match) { page = match[1]; } else if (link.hasClass('prev')) { var current = container.find('.tlr-pagination-' + listId + ' .current'); if (current.length) { page = parseInt(current.text()) - 1; } } else if (link.hasClass('next')) { var current = container.find('.tlr-pagination-' + listId + ' .current'); if (current.length) { page = parseInt(current.text()) + 1; } } // إظهار مؤشر تحميل (اختياري) container.css('opacity', '0.6'); $.ajax({ url: tlr_ajax.ajax_url, type: 'POST', data: { action: 'tlr_load_titles', list_id: listId, page: page, nonce: tlr_ajax.nonce }, success: function(response) { container.css('opacity', '1'); if (response.success) { // استبدال محتوى القائمة فقط var newHtml = response.data.html; var newPagination = ''; // إعادة بناء روابط الترقيم if (response.data.max_pages > 1) { newPagination = '
'; // إضافة رابط السابق إذا لم نكن في الصفحة الأولى if (response.data.current_page > 1) { newPagination += ''; } // إضافة أرقام الصفحات for (var i = 1; i <= response.data.max_pages; i++) { if (i == response.data.current_page) { newPagination += '' + i + ''; } else { newPagination += '' + i + ''; } } // إضافة رابط التالي إذا لم نكن في الصفحة الأخيرة if (response.data.current_page < response.data.max_pages) { newPagination += ''; } newPagination += '
'; } // تحديث المحتوى container.html(newHtml + newPagination); } } }); }); }); });