Tùy chọn phân trang trong wordpress sử dụng ajax 1 Tháng mười một, 2018 Akasa Code WP, Wordpress Code hiện thị <div class="col-12 col-sm-12 col-md-12 ajax-content-cat"> <div class="col-box-items-blogs"> <div class="row"> <div class="col-12 col-sm-12 col-md-6"> <div class="aaaalkll-left"> <?php $wp1 = new WP_Query(array( 'post_type'=>'post', 'post_status'=>'publish', 'cat' => $cat, 'posts_per_page'=> 1)); while ($wp1->have_posts()) : $wp1->the_post(); ?> <div class="img-title-category-templates"> <div class="img-category-templates position-relative"> <a href="<?php the_permalink();?>"><?php the_post_thumbnail('full');?></a> <span class="position-absolute"><?php the_category();?></span> </div> <div class="title-category-templates"> <a href="<?php the_permalink();?>"><?php the_title();?></a> <div class="author-time-date-blogs pb-2"> <li class="font-weight-bold"><?php the_author();?></li> <li> - </li> <li><?php the_time('d/m/Y');?></li> </div> </div> <div class="exacerbate-category-templates"> <?php the_excerpt();?> </div> </div> <?php endwhile; wp_reset_query(); wp_reset_postdata(); ?> </div> </div> <div class="col-12 col-sm-12 col-md-6"> <div class="aaaalkll-right"> <?php $wp1 = new WP_Query(array( 'post_type'=>'post', 'cat' => $cat, 'showposts'=>4, 'offset'=>1 )); while ($wp1->have_posts()) : $wp1->the_post(); ?> <div class="img-title-category-templates mb-3"> <div class="row"> <div class="col-12 col-sm-6 col-md-4"> <div class="img-category-templates"> <a href="<?php the_permalink();?>"><?php the_post_thumbnail('full');?></a> </div> </div> <div class="col-12 col-sm-6 col-md-8"> <div class="title-category-templates"> <a href="<?php the_permalink();?>"><?php the_title();?></a> <span class="pt-2 pb-2" style="font-size: 10px;"><?php the_time('d/m/y');?></span> </div> </div> </div> </div> <?php endwhile; wp_reset_query(); wp_reset_postdata(); ?> </div> </div> </div> </div> </div> //Code phân trang riêng <div class="pagination-template mt-3 mb-3"> <span class="action-pagination-cat btn-action-prev" data-name="prev" data-cat="<?=$cat; ?>" data-page="0"><</span> <span class="action-pagination-cat btn-action-next" data-name="next" data-cat="<?=$cat; ?>" data-page="1">></span> </div> Code load ajax add_action( 'wp_ajax_cat_ipagenation', 'cat_ipagenation' ); add_action( 'wp_ajax_nopriv_cat_ipagenation', 'cat_ipagenation' ); function cat_ipagenation(){ if(isset($_POST['name'],$_POST['cat'],$_POST['page'])){ $page=(int) $_POST['page']; $cat=(int) $_POST['cat']; $name=$_POST['name']; $term_cat=get_term( $cat); $total=ceil($term_cat->count/5); $curent=0; $response=array(); if($name=="prev" || $name=="next"){ $curent=$page; $offset=$curent*5; $next=min($curent+1,$total-1); $prev=max(0,$page); if($name=="prev"){ $prev=max(0,$prev-1); $next=max(1,$page); } if($name=="next"){ $prev=min($prev,$total-2); } $html=' '; $wp1 = new WP_Query(array( 'post_type'=>'post', 'post_status'=>'publish', 'cat' => $cat, 'offset'=>$offset, 'posts_per_page'=> 1)); $term1=""; while ($wp1->have_posts()) : $wp1->the_post(); $term1.=' '.get_the_post_thumbnail(get_the_ID(),'full').' '.get_the_category(get_the_ID()).' '.get_the_title(get_the_ID()).' '.get_the_author(get_the_ID()).' - '.get_the_time(get_the_ID(),'d/m/Y').' '.get_the_excerpt(get_the_ID()).' '; endwhile; wp_reset_query(); wp_reset_postdata(); $html.=$term1; $html.=' '; $html.=' '; $term2=""; $wp1 = new WP_Query(array( 'post_type'=>'post', 'post_status'=>'publish', 'posts_per_page'=>4, 'cat' => $cat, 'offset'=>$offset+1 )); while ($wp1->have_posts()) : $wp1->the_post(); $term2.=' '.get_the_post_thumbnail(get_the_ID(),'thumbnail').' '.get_the_title(get_the_ID()).' '.get_the_time(get_the_ID(),'d/m/y').' '; endwhile; wp_reset_query(); wp_reset_postdata(); $html.=$term2; $html.=' '; $response['html']=$html; $response['next']=$next; $response['prev']=$prev; wp_send_json( $response); } } die(); } 0 0 đánh giá Đánh giá bài viết Please wait...
1 Tháng mười một, 2018 Akasa Code WP, Wordpress Code hiện thị <div class="col-12 col-sm-12 col-md-12 ajax-content-cat"> <div class="col-box-items-blogs"> <div class="row"> <div class="col-12 col-sm-12 col-md-6"> <div class="aaaalkll-left"> <?php $wp1 = new WP_Query(array( 'post_type'=>'post', 'post_status'=>'publish', 'cat' => $cat, 'posts_per_page'=> 1)); while ($wp1->have_posts()) : $wp1->the_post(); ?> <div class="img-title-category-templates"> <div class="img-category-templates position-relative"> <a href="<?php the_permalink();?>"><?php the_post_thumbnail('full');?></a> <span class="position-absolute"><?php the_category();?></span> </div> <div class="title-category-templates"> <a href="<?php the_permalink();?>"><?php the_title();?></a> <div class="author-time-date-blogs pb-2"> <li class="font-weight-bold"><?php the_author();?></li> <li> - </li> <li><?php the_time('d/m/Y');?></li> </div> </div> <div class="exacerbate-category-templates"> <?php the_excerpt();?> </div> </div> <?php endwhile; wp_reset_query(); wp_reset_postdata(); ?> </div> </div> <div class="col-12 col-sm-12 col-md-6"> <div class="aaaalkll-right"> <?php $wp1 = new WP_Query(array( 'post_type'=>'post', 'cat' => $cat, 'showposts'=>4, 'offset'=>1 )); while ($wp1->have_posts()) : $wp1->the_post(); ?> <div class="img-title-category-templates mb-3"> <div class="row"> <div class="col-12 col-sm-6 col-md-4"> <div class="img-category-templates"> <a href="<?php the_permalink();?>"><?php the_post_thumbnail('full');?></a> </div> </div> <div class="col-12 col-sm-6 col-md-8"> <div class="title-category-templates"> <a href="<?php the_permalink();?>"><?php the_title();?></a> <span class="pt-2 pb-2" style="font-size: 10px;"><?php the_time('d/m/y');?></span> </div> </div> </div> </div> <?php endwhile; wp_reset_query(); wp_reset_postdata(); ?> </div> </div> </div> </div> </div> //Code phân trang riêng <div class="pagination-template mt-3 mb-3"> <span class="action-pagination-cat btn-action-prev" data-name="prev" data-cat="<?=$cat; ?>" data-page="0"><</span> <span class="action-pagination-cat btn-action-next" data-name="next" data-cat="<?=$cat; ?>" data-page="1">></span> </div> Code load ajax add_action( 'wp_ajax_cat_ipagenation', 'cat_ipagenation' ); add_action( 'wp_ajax_nopriv_cat_ipagenation', 'cat_ipagenation' ); function cat_ipagenation(){ if(isset($_POST['name'],$_POST['cat'],$_POST['page'])){ $page=(int) $_POST['page']; $cat=(int) $_POST['cat']; $name=$_POST['name']; $term_cat=get_term( $cat); $total=ceil($term_cat->count/5); $curent=0; $response=array(); if($name=="prev" || $name=="next"){ $curent=$page; $offset=$curent*5; $next=min($curent+1,$total-1); $prev=max(0,$page); if($name=="prev"){ $prev=max(0,$prev-1); $next=max(1,$page); } if($name=="next"){ $prev=min($prev,$total-2); } $html=' '; $wp1 = new WP_Query(array( 'post_type'=>'post', 'post_status'=>'publish', 'cat' => $cat, 'offset'=>$offset, 'posts_per_page'=> 1)); $term1=""; while ($wp1->have_posts()) : $wp1->the_post(); $term1.=' '.get_the_post_thumbnail(get_the_ID(),'full').' '.get_the_category(get_the_ID()).' '.get_the_title(get_the_ID()).' '.get_the_author(get_the_ID()).' - '.get_the_time(get_the_ID(),'d/m/Y').' '.get_the_excerpt(get_the_ID()).' '; endwhile; wp_reset_query(); wp_reset_postdata(); $html.=$term1; $html.=' '; $html.=' '; $term2=""; $wp1 = new WP_Query(array( 'post_type'=>'post', 'post_status'=>'publish', 'posts_per_page'=>4, 'cat' => $cat, 'offset'=>$offset+1 )); while ($wp1->have_posts()) : $wp1->the_post(); $term2.=' '.get_the_post_thumbnail(get_the_ID(),'thumbnail').' '.get_the_title(get_the_ID()).' '.get_the_time(get_the_ID(),'d/m/y').' '; endwhile; wp_reset_query(); wp_reset_postdata(); $html.=$term2; $html.=' '; $response['html']=$html; $response['next']=$next; $response['prev']=$prev; wp_send_json( $response); } } die(); } 0 0 đánh giá Đánh giá bài viết Please wait...