Created
November 4, 2017 05:03
-
-
Save phucdohong96/b173fea5dc9e83a2242c98725d759772 to your computer and use it in GitHub Desktop.
Loop with custom pagination ajax
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function pager_loop_function() { | |
| ob_start(); | |
| $paged1 = isset( $_GET['paged1'] ) ? (int) $_GET['paged1'] : 1; | |
| $args1 = array( | |
| 'post_type' => 'post', | |
| 'paged' => $paged1, | |
| 'posts_per_page' => 6, | |
| ); | |
| echo '<div id="event1">'; | |
| $query1 = new WP_Query( $args1 ); | |
| $count = 0; | |
| while ( $query1->have_posts() ) : $query1->the_post(); | |
| $id = get_the_ID(); | |
| $title = get_the_title(); | |
| $image = get_the_post_thumbnail($id,'large'); | |
| $excerpt = get_the_excerpt(); | |
| $link = get_permalink ($id); | |
| $content = get_the_content(); | |
| $author = get_the_author(); | |
| ?> | |
| <div>HTMl</div> | |
| <?php | |
| $count++; | |
| endwhile; | |
| echo '<div class="clearfix"></div>'; | |
| /*---------------------- Pagination 1 ------------------------*/ | |
| $pag_args1 = array( | |
| 'format' => '?paged1=%#%', | |
| 'current' => $paged1, | |
| 'total' => $query1->max_num_pages, | |
| 'add_args' => array( 'paged2' => $paged2 ) | |
| ); | |
| $pager1 = paginate_links( $pag_args1 ); | |
| echo '<div class="shortcode_pager">'.$pager1.'</div>'; | |
| /*---------------------- End ------------------------*/ | |
| echo '</div>'; | |
| //End Div Ajax | |
| ?> | |
| <!-- Script Pagination Ajax --> | |
| <script type="text/javascript"> | |
| jQuery(function($) { | |
| $('#event1').on('click', '.shortcode_pager a', function(e){ | |
| e.preventDefault(); | |
| var link = $(this).attr('href'); | |
| $('#event1').fadeOut(100, function(){ | |
| $(this).load(link + ' #event1', function() { | |
| $(this).fadeIn(100); | |
| }); | |
| }); | |
| }); | |
| }); | |
| </script> | |
| <?php | |
| wp_reset_postdata(); | |
| return ob_get_clean(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment