Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // AJAX file
- $(document).ready(function() {
- // ajax запрос на load more
- let currentPage = 1;
- $('#load-more').on('click', function() {
- currentPage++; // Do currentPage + 1, because we want to load the next page
- $(this).removeData('catslug'); // remove value of data-slug from cache
- $.ajax({
- type: 'POST',
- url: '/wp-admin/admin-ajax.php',
- dataType: 'json',
- data: {
- action: 'load_more_projects',
- paged: currentPage,
- category: $(this).data('catslug'),
- },
- success: function (res) {
- if(currentPage >= res.max) {
- $('#load-more').hide();
- }
- $('.post-filter').append(res.html);
- }
- });
- });
- // ajax запрос на фильтр
- $('.cat-list_item').on('click', function() {
- $('.cat-list_item').removeClass('active');
- $(this).addClass('active');
- $('#load-more').attr('data-catslug', $(this).data('slug')); //write category data to load-more button
- $('#load-more').show(); //Show load more button if hided
- $.ajax({
- type: 'POST',
- url: '/wp-admin/admin-ajax.php',
- dataType: 'json',
- data: {
- action: 'filter_projects',
- category: $(this).data('slug'),
- },
- success: function(res) {
- currentPage = 1; //set the current page to 1 after filter button click
- $('.post-filter').html(res.html);
- }
- })
- });
Advertisement
Add Comment
Please, Sign In to add comment