I’m using the paginate_links()
function (source) and have a question about the args.
I have only added the total
arg and it seems to work fine with different permalink settings. Does this mean I can omit the base
and format
arg, so use the default settings instead? Because both are added in most examples I find online, so I have doubt about this.
Guido
]]>I noticed strange thing in my website products search results page when searching product attribute like color.
Pagination is build with paginate_links(), it creates page numbers correctly but when clicking onto 2nd page it leads to error not found page.
This happens only when searching via attribute, when i search via product title pagination works properly.
Posts per page number in WP Customize is the same as in the WP Query i have in my search results page.
Any ideas why this happen are much appreciated.
Thank you
All I know is that it worked without getting the escape warnings with and without $args, and I didn’t create an args variable anywhere, but maybe Underscores has it in some file. So what is $args and why do you need to use it?
]]>I’d like to be about to add things like aria-label=”Next Page” or aria-label=”Page [#Number]”
Thank you.
https://developer.www.ads-software.com/reference/functions/paginate_links/
function pagination_bar() {
global $wp_query;
$total_pages = $wp_query->max_num_pages;
$big = 999999999; // need an unlikely integer
if ($total_pages > 1){
$current_page = max(1, get_query_var('paged'));
echo paginate_links(array(
//'base' => get_pagenum_link(1) . '%_%',
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'aria_current' => page,
'format' => '/page/%#%',
'current' => $current_page,
'total' => $total_pages,
));
}
}
]]>paginate_links
function to generate custom pagination for a page:
echo paginate_links(array(
'base' => get_pagenum_link(1) . '%_%',
'format' => '/page/%#%',
'current' => $current_page,
'total' => $total_pages,
'prev_text' => __('? Pervious'),
'next_text' => __('Next ?'),
'add_args' => array()
));
The problem happens when browsing the pages, an extra slash added to the URLs of paginations, so instead of https://website.com/page/1
it becomes https://website.com//page/1/
. If I will remove the first slash from format 'format' => 'page/%#%'
, the URL will be like that: https://website.compage/1/
.
What cause the extra slash to appear?
]]>I managed to control the number of posts to display on an archive post page using the code below:
$args = array( ‘post_type’ => ‘post’,
‘post_status’=>’publish’,
‘posts_per_page’ => 10,
‘category_name’ => ‘NEWS’,
‘paged’ => $paged,
);
However, upon clicking the Next Page link in the pagination, the browser returns ERROR 404. The code for the pagination is as follows:
echo paginate_links( array( ‘format’ => ‘page/%#%’, ‘current’ => $paged, ‘total’ => $the_query->max_num_pages, ‘mid_size’ => 2, ‘prev_text’ => __(‘« Prev Page’), ‘next_text’ => __(‘Next Page »’) ) );
ERROR 404 mentioned above is resolved only and if only the max number of posts to display is set to below the value of ‘posts_per_page’ on the WP admin screen, which I found inconvenient because I want to show different numbers of posts on paginated pages across different archive post pages.
Is there a way to override the WP’s max number of posts to display using paginate_links()?
]]><?php endwhile; ?>
<!–Post navigations–>
<?php
global $wp_query;
$big = 999999999; // need an unlikely integer
echo paginate_links( array(
‘base’ => str_replace( $big, ‘%#%’, esc_url( get_pagenum_link( $big ) ) ),
‘format’ => ‘?paged=%#%’,
‘current’ => max( 1, get_query_var(‘paged’) ),
‘total’ => $wp_query->max_num_pages
) );
?>
<?php else: ?>
I’m building a blog and it almost works the way I want (so that’s great). The only thing that doesn’t work is the pagination section. I would like it to look like this:
? Prev 1 … 3 4 5 6 7 … 9 Next ?
(Anything close would do fine.)
But how?
This is what I got thus far.
<?php
// WP_Query arguments
$args = array (
'post_status' => 'publish',
'pagination' => true,
'posts_per_page' => '5',
'order' => 'DESC',
'orderby' => 'date',
'paged' => $paged,
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $wp_query->max_num_pages,
'before_page_number' => '<span>Page </span>'
);
// The Query
$query = new WP_Query( $args );
$paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
$big = 999999999; // need an unlikely integer
// The Loop
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
$cats = '';
foreach( get_the_category( $recent["ID"] ) as $cat ) { $cats .= ' ' . $cat->slug; }
echo '<header><h4>' . get_the_title() . '</h4><p>'. get_the_date() . ' - <span class="icon ' . $cats .'"></span></p></header><p>'. get_the_content() . '</p>';
}
} else {
echo paginate_links();
}
// Restore original Post Data
wp_reset_postdata();
?>
I am not very familiar with php, so I hope anyone of you can find a few minutes to help me out here.
Thanks very much in advance!
Meindert
]]>i use in my Plugin-Backend some Custom Tables and i want to paginate them with paginate_links.
Now i have three “little” Problems. Under my table exist the Paginationlinks but…
1.) If click on Page 2 it shows me the Datasets correctly, but i cant go back to Page 1.
Page 1 is not marked as a link!!!
2.) If i am on Page 3 and click on “Next” it goes to Page 2. The same if i am on Page 6 e.g.
3.) The Paginationlinks are 123..6 Next. If i am on Page 3 i dont see 4 or 5
Here is my (terrible) Code
function mitarbeiter_loeschen() {
global $wpdb;
$table_lagerma = $wpdb->prefix . "za_lagerma";
// Wurde das Formular abgeschickt dann entsprechend l?schen
if (isset ( $_REQUEST ["do"] ) && $_REQUEST ["do"] == "loeschen") {
$loeschma = $_POST ['maid'];
foreach ( $loeschma as $loeschid ) {
$wpdb->query ( $wpdb->prepare ( "DELETE from $table_lagerma where id = %d", $loeschid ) );
}
}
echo '<p><div class="wrap">';
echo '<h2>Mitarbeiter loeschen!!!</h2>';
echo 'Hier werden Mitarbeiter geloescht</p>';
echo '<hr>';
$per_page = 6;
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$page = intval ( $_GET ['paged'] );
$total_pages = ceil ( $wpdb->get_var ( "SELECT COUNT(*) FROM $table_lagerma" ) / $per_page );
$sql = $wpdb->prepare ( "SELECT * FROM $table_lagerma ORDER BY nname ASC LIMIT %d, %d", max ( $page - 1, 0 ) * $per_page, $per_page );
$mitarbeiter = $wpdb->get_results ( $sql );
echo '<form name="mitarbeiter_loeschen" method="post" action="">';
echo '<h4> Angelegte Mitarbeiter<h4>';
echo '<table><tr><td></td><td>Vorname</td><td>Nachname</td><td>Logistik</td></tr>';
foreach ( $mitarbeiter as $ma ) {
echo '<tr><td><input type="checkbox" name="maid[]" value="' . $ma->id . '"></td>';
echo '<td>' . $ma->vname . '</td>';
echo '<td>' . $ma->nname . '</td>';
echo '<td>' . $ma->logistik . '</td></tr>';
}
echo '</table><input type="submit" id="buttonloeschen" value="Loeschen" onclick="return confirm(\'Wirklich loeschen?\');" />';
echo '<input name="do" type="hidden" id="check" value="loeschen"></form></div></p>';
$big = 999999999; // dummy
echo '<p>';
$paginate_links = paginate_links ( array (
'base' => @add_query_arg('paged','%#%'),
'format' => '?paged=%#%',
//'current' => max( 1, $paged),
'current' => max( 1, get_query_var('paged') ),
'total' => $total_pages
) );
echo $paginate_links;
echo '</p>';
}
]]>