Question: How can we integrate pagination with list of categories in wordPress?
Answer: Below are code to integrate pagination with list of categories in wordPress.
$args = array( 'parent' => 0, 'hide_empty' => 0 ); $categories = get_categories( $args ); $cat = ceil(count( $categories )/5); $j=0; $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $posts_per_page = 5; $offset = ($posts_per_page * $paged) - 5 ; $args = array( 'orderby' => 'name', 'parent' => 0, 'hide_empty' => 0, 'number' => $posts_per_page, 'offset' => $offset, 'posts_per_page' => 5, 'paged' => $paged //'exclude' => '1,3,24,9' ); $categories = get_categories( $args ); foreach ( $categories as $category ) { $j++; echo '' . $category->name . '
'; } $big = 999999999; // need an unlikely integer echo ''; echo paginate_links( array( 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), 'format' => '?paged=%#%', 'prev_text' => __('<<'), 'next_text' => __('>>'), 'current' => max( 1, get_query_var('paged') ), 'total' => $cat ) ); echo '';
No comments:
Post a Comment