Below code will fetch all posts from all categories. Here we have given limit for one page as 10. Then you have to check the permalink structure of ur site. Please check the code I think it will work.
/* it will fetch all posts */
$post_args = array(
'posts_per_page' => -1,
'orderby' => 'post_date',
'order' => 'DESC',
'post_type' => 'post',
'post_status' => 'publish',
);
$all_posts = get_posts( $post_args );
$post_count = count( $all_posts );
/* if post_count is greater than 0 */
if ( $post_count > 0 ) {
$limit = 10;
/* this is for getting the last post number */
if ( get_query_var( 'paged' ) ) {
$current_page = get_query_var( 'paged' );
} else {
$current_page = 1;
}
$permalink_structure = get_option( 'permalink_structure' );
$format = empty( $permalink_structure ) ? '&page=%#%' : 'page/%#%/';
$total_pages = ceil( $post_count / $limit );
$start = $current_page * $limit - $limit;
}
/* it will fetch posts under limit for all categories */
$post_args = array(
'posts_per_page' => $limit,
'offset' => $start,
'orderby' => 'post_date',
'order' => 'DESC',
'post_type' => 'post',
'post_status' => 'publish',
);
$current_posts = get_posts( $post_args );
?>
<!-- this is for showing pagination -->
<div class="tablenav">
<div class="tablenav-pages">
<?php
echo paginate_links(
array(
'current' => $current_page,
'prev_text' => '« ' . __( 'Prev' ),
'next_text' => __( 'Next' ) . ' »',
'base' => add_query_arg( 'paged', '%#%' ),
'format' => $format,
'total' => $total_pages
)
);
?>
</div>
</div>
<!-- then here you can run the loop to show posts from $current_posts -->
<?php
/* if the posts are present */
if ( !empty( $current_posts ) ) {
foreach ( $current_posts as $post ) {
/* the code for showing posts */
}
}
http://localhost/sdd/%postname%
<br/> @SabitaSahoo i'm usingget_pagenum_link
to generate the link.