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
Normal pagination
[1, 2, 3, 4, 5]
Select option
<<NEXT [SELECT] PREV>>
<?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
PHP Dom Textcontent VS Nodevalue
How to Retrieve Date from Table Cell Using PHPspreadsheet
How to Avoid Request Entity Too Large 413 Error
Str_Replace() for Multiple Value Replacement
PHP Dynamically Create CSV: Skip the First Line of a CSV File
Php: $_Server Variables: $_Server['Http_Host'] VS $_Server['Server_Name']
PHP Curl: Curlopt_Connecttimeout VS Curlopt_Timeout
Laravel 4.2 Says My Application Is in Production. How to Turn This Off
Php: How to Read a File Live That Is Constantly Being Written To
Storing Leading Zeros of Integers in MySQL Database as Integer
Looping Through a Simplexml Object, or Turning the Whole Thing into an Array
PHP Considers Null Is Equal to Zero
Combining And/Or Eloquent Query in Laravel
Best Way to Get Hostname with PHP