How to load posts only after clicking a button?
-
Hello! I’m using ALM on a tag page. Posts are loaded via foreach. In its parameters I specified ‘posts_per_page’ => 8. However, after loading the pages are loaded, in addition to these 8 posts, the next 8 are also loaded (which I specified in the shortcode). They should load only when the button is pressed. How to do it?
This is my code:<?php $current_page = !empty( $_GET['page'] ) ? $_GET['page'] : 1; $term = get_queried_object(); $numberposts = get_sub_field('количество_товаров'); $loadposts = get_sub_field('кнопка_загрузки_постов'); $args = [ 'post_type' => 'product', 'posts_per_page' => 8, 'tag' => $term -> slug, 'paged' => $current_page ]; $posts = get_posts($args); $counter = 0; foreach( $posts as $post ){ setup_postdata( $post ); $counter++; get_template_part('template-parts/product'); switch ($counter){ case $case: if(is_page(148)):?> <div class="banner" style="background: url('<?php the_sub_field('low-banner_background')?>') no-repeat; background-size: cover;"> <div class="low-banner__content"> <h1><?php the_sub_field('low-banner_title')?></h1> <p><?php the_sub_field('low-banner_description')?></p> </div> </div> <? endif; ?> <?php break; } ?> <?php } wp_reset_postdata();?> </div> <?php echo do_shortcode('[ajax_load_more container_type="div" post_type="product" posts_per_page="8" images_loaded="true" placeholder="true" button_label="Загрузить еще" scroll="false" tag="'. $term->slug .'" offset="8"]'); ?>
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘How to load posts only after clicking a button?’ is closed to new replies.