Wordpress- I want to add pagination with list of categories

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 '';

No comments:

Post a Comment