javascript - How to save PHP variable in loop after AJAX requests more posts? -
i have been looking @ code far long , getting can me!
i building wordpress site, , main blog page, want display content tiles, every 3 or 7, want display promo content post-type. can fine, when add load more posts button, resets counter have keeping track of promo content 0, therefore showing first 2 promo pieces on , on each new load.
i appreciate help. i'm going in circles now.
the important parts of home.php file :
<div class="blog-post-tiles"> <?php //variables $counter = 0; $promo_counter = 0; $args = array( 'post_type' => 'promo', ); //$postlist = new wp_query( $args ); $postlist = get_posts($args); $posts = array(); foreach ( $postlist $post ) { $promo_posts_array[] += $post->id; } ?> <?php if ( have_posts() ) : ?> <?php $query = new wp_query( $query_string.'&cat=-16' ); while ( $query->have_posts() ) : $query->the_post() ?> <?php // print post loop get_template_part( 'template-parts/content', get_post_format() ); $counter++; //display promo content ever 3rd or 10th spot if (($counter == 3) || ($counter % 10 == 0) || ($counter % 10 == 3)) { if ($promo_counter < count($promo_posts_array)){ $print_post = $promo_posts_array[$promo_counter]; $promo_thumbnail_src = wp_get_attachment_image_src( get_post_thumbnail_id($print_post), array( 200,200 ), false, ''); ?> <div class="posts_page_tile promo-tile" id="id-<?php echo $print_post; ?>"> <div class="entry-content"> <div class="promo-image" style="background-image:url('<?php echo $promo_thumbnail_src[0]; ?>'); background-color:<?php echo get_post_meta($print_post, 'bgcolor', true) ?>"> <h3><a href="<?php echo get_post_meta($print_post, 'cta_link', true); ?>"><?php echo get_the_title($print_post); ?></a></h3> <div class="promo_button_white_border"><a href="' . get_post_meta($print_post, 'cta_link', true) . '"><?php echo get_post_meta($print_post, 'cta', true); ?></a> </div> </div> </div> </div> <?php } $promo_counter++; wp_reset_postdata(); } ?> <?php endwhile; ?>
i'm using this load more posts plugin.
Comments
Post a Comment