Wordpress Paginate_Links - How to Use It

WordPress paginate_links - how to use it?

Pagination Like : Prev 1 2 3 Next

<?php 
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

$data= new WP_Query(array(
'post_type'=>'YOUR_POST_TYPE', // your post type name
'posts_per_page' => 3, // post per page
'paged' => $paged,
));

if($data->have_posts()) :
while($data->have_posts()) : $data->the_post();
// Your code
endwhile;

$total_pages = $data->max_num_pages;

if ($total_pages > 1){

$current_page = max(1, get_query_var('paged'));

echo paginate_links(array(
'base' => get_pagenum_link(1) . '%_%',
'format' => '/page/%#%',
'current' => $current_page,
'total' => $total_pages,
'prev_text' => __('« prev'),
'next_text' => __('next »'),
));
}
?>
<?php else :?>
<h3><?php _e('404 Error: Not Found', ''); ?></h3>
<?php endif; ?>
<?php wp_reset_postdata();?>

Could you please try above code? I think it's helpful for you.

Wordpress paginate_links select option

I have created an additional plugin for myself that generates either a

  1. Normal pagination [1, 2, 3, 4, 5]

  2. Select option <<NEXT [SELECT] PREV>>

Change the config.php file and call the function (rename it if you would like)

<?php jagmit_paging_nav(); ?>

https://github.com/jagmitg/Wordpress-Select-Pagination

WordPress paginate_links() Customization

Get your data with type = array. You will get an array of the links and you can do the html markup yourself.


$pages = array(
'type' => 'array'

);

$links = paginate_links($pages);

foreach($links as $link){
// Render the HTML here
}

Wordpress paginate_links - first page always the same as current page

The array for paginate_links needed the following base:

'base' => @add_query_arg('paged1','%#%'),

That fixed it. Here is the full code for clarity:

            $pag_args1 = array(
'base' => @add_query_arg('paged1','%#%'),
'format' => '?paged1=%#%',
'current' => $paged1,
'total' => $query1->max_num_pages
);


Related Topics



Leave a reply



Submit