Tuesday, 26 October 2021

123.pagination and load more in wordpress

  <section class="ftco-section bg-light">

      <div class="container">
        <div class="row">
          <?php
         
            $wpb_all_query = new WP_Query( array(
            // 'posts_per_page' => 6,
            'post_type'=>'post', 'post_status'=>'publish',
            'paged' => get_query_var('paged') ? get_query_var('paged') : 1) );


          if ( $wpb_all_query->have_posts() ) :
            while ( $wpb_all_query->have_posts() ) : $wpb_all_query->the_post();
     
      $imag_url= get_the_post_thumbnail_url();    
          ?>  
          <div class="col-md-4 ftco-animate life-style">
            <div class="blog-entry">
              <span href="#" class="block-20" style="background-image: url(<?php echo $imag_url; ?>);"></span>
              <div class="text pt-3 pb-4 px-4">
                <div class="meta">                
                  <div><span class="life_style_text"><?php the_title(); ?></span></div>                  
                </div>
                <h3 class="heading"><a href="#" ><?php the_content(); ?></a></h3>
                <p class="clearfix">
                <?php the_content(); ?>
                </p>
              </div>
            </div>
          </div>
          <?php endwhile; ?>
      <?php else:?>
     
        no post found
   
      <?php endif; wp_reset_postdata(); ?>
         
         
        </div>
       
        <?php /*
          <div class="row no-gutters my-5 ">
          <div class="col text-center">
            <div class="block-27">
            <div style="clear:both;">
            <ul>
           
            <li>
            <?php
           
            $big = 999999999; // need an unlikely integer
            echo paginate_links( array(
                'base' => str_replace( $big, '%#%', get_pagenum_link( $big ) ),
                'format' => '?paged=%#%',
                'current' => max( 1, get_query_var('paged') ),
                'total' => $wpb_all_query->max_num_pages
            ) );
           
            wp_reset_postdata(); ?>
            </li>
           
            </ul>
            </div>              
            </div>
          </div>
          </div>
          */?>
         
          <div class="form-group text-center">
          <a href="" class="load-more" id="seeMore">Load More</a>
          </div>
         



      </div>
    </section>




<script>
  $(document).ready(function(){
  $(".life-style").slice(0,6).show();
  $("#seeMore").click(function(e){
    e.preventDefault();
    $(".life-style:hidden").slice(0,6).fadeIn("slow");
   
    if($(".life-style:hidden").length == 0){
       $("#seeMore").fadeOut("slow");
      }
  });
})
  </script>