Task 7177 | Исправлена ajax подгрузка в категориях блога

pull/36/head
parent 48678b81ce
commit f4fe03c18d
  1. 8
      wp-content/themes/cosmopet/modules/blog/components/archive/component-controller.php
  2. 3
      wp-content/themes/cosmopet/modules/blog/module-ajax-controller.php
  3. 3
      wp-content/themes/cosmopet/templates/blog/blog-archive.twig

@ -11,10 +11,14 @@ wp_localize_script('blog-archive-posts-ajax-js', 'ajax', array(
'ajax_url' => admin_url('admin-ajax.php'),
));
global $wp_query;
$context = Timber::context();
$context['blog_title'] = get_field('blog_title', 'options');
$context['blog_desc'] = get_field('blog_desc', 'options');
$context['post_count'] = wp_count_posts()->publish; // Количество опубликованных постов
$context['total_pages'] = ceil($context['post_count'] / get_option('posts_per_page')); // Общее количество страниц
$context['total_pages'] = $wp_query->max_num_pages;
if (is_category()) {
$context['category'] = get_queried_object();
}
Timber::render('blog/blog-archive.twig', $context);

@ -32,7 +32,8 @@ function get_posts_by_page_and_category($paged = 1, $category = '') {
function ajax_load_blog_posts() {
$page_num = isset($_POST['page_num']) ? sanitize_text_field($_POST['page_num']) : '';
$context = Timber::context();
$context['posts'] = get_posts_by_page_and_category($page_num);
$category = $_POST['category'];
$context['posts'] = get_posts_by_page_and_category($page_num, $category);
$html = Timber::compile('/blog/news-list.twig', $context);
echo $html;
wp_die();

@ -30,6 +30,9 @@
<form id="ajax-load-blog" data-total="{{ total_pages }}">
<input type="hidden" name="page_num" id="page_num" value="1">
<input type="hidden" name="action" value="load_blog_posts">
{% if fn('is_category') %}
<input type="hidden" name="category" id="category_id" value="{{ category.slug }}">
{% endif %}
<button class="anons-article__more-link" >
{{ function('pll_e', 'ПОКАЗАТЬ ЕЩЁ') }}
</button>

Loading…
Cancel
Save