Last active
October 7, 2017 05:49
-
-
Save phucdohong96/4a9bdff9a3dae1ab6bbd3be47f26bddf to your computer and use it in GitHub Desktop.
Custom Loop With Muilti Pagination
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 loop_custom_function( $atts ) { | |
| ob_start(); | |
| $paged1 = isset( $_GET['paged1'] ) ? (int) $_GET['paged1'] : 1; | |
| $paged2 = isset( $_GET['paged2'] ) ? (int) $_GET['paged2'] : 1; | |
| $args1 = array( | |
| 'post_type' => 'custom_post_type', | |
| 'paged' => $paged1, | |
| 'posts_per_page' => 6, | |
| ); | |
| $query1 = new WP_Query( $args1 ); | |
| $count = 0; | |
| while ( $query1->have_posts() ) : $query1->the_post(); | |
| $id = get_the_ID(); | |
| ?> | |
| <div>HTML Content</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>'; | |
| // Custom Loop with Pagination 2 | |
| $args2 = array( | |
| 'post_type' => 'custom_post_type', | |
| 'paged' => $paged2, | |
| 'posts_per_page' => 6, | |
| ); | |
| $query2 = new WP_Query( $args2 ); | |
| $count_query2 = 0; | |
| while ( $query2->have_posts() ) : $query2->the_post(); | |
| $id = get_the_ID(); | |
| ?> | |
| <div>HTML Content</div> | |
| <?php | |
| $count_query2++; | |
| endwhile; | |
| echo '<div class="clearfix"></div>'; | |
| /*----------------------Pagination 2------------------------*/ | |
| $pag_args2 = array( | |
| 'format' => '?paged2=%#%', | |
| 'current' => $paged2, | |
| 'total' => $query2->max_num_pages, | |
| 'add_args' => array( 'paged1' => $paged1 ) | |
| ); | |
| $pager2 = paginate_links( $pag_args2 ); | |
| echo '<div class="shortcode_pager">'.$pager2.'</div>'; | |
| wp_reset_postdata(); | |
| return ob_get_clean(); | |
| } |
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 | |
| include('cutom_loop_shortcode.php'); | |
| add_shortcode('loop_custom_shortcode', 'loop_custom_function'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment