paginate_links ignorieren mein Format
1 Antworten
- Stimmen
-
- 2017-08-16
Dieser Teil:
'base' => str_replace( 999999999, '%#%', esc_url( get_pagenum_link( 999999999 ) ) ),
generierteinen
page
Teil wie diesen:'base' => http://example.tld/page/%#%/
Wenn wireinen Blickin
paginate_links()
werfen Wir sehen die Standardeinstellung:'base' => $pagenum_link, // http://example.com/all_posts.php%_% : // %_% is replaced by format (below) 'format' => $format, // ?page=%#% : %#% is replaced by the page number
wobei der Inline-Kommentarbesagt,dass
%_%
durch das Formatersetzt wird.In der Dokumentation heißtes außerdem:
Ein Beispielfür das Argument
‘base’
ist"http://example.com/all_posts.php%_%"
und der‘%_%’
sinderforderlich. Das‘%_%’
wird durch den Inhalt des Arguments‘format’
ersetzt. Ein Beispielfür das Argument‘format’
ist"?page=%#%"
und das Argument '% #%'istes auch erforderlich. Der‘%#%’
wird durch die Seitenzahlersetzt.Wenn wir das verwenden:
'base' => '%_%'
dannentsprichtes dem Argument
format
.Hieristeine Modifikation des OP-Beispiels:
echo paginate_links( [ 'base' => '%_%', 'total' => $query->max_num_pages, 'current' => $current, 'format' => '?p-page=%#%', 'show_all' => false, 'type' => 'plain', 'end_size' => 2, 'mid_size' => 1, 'prev_next' => true, 'prev_text' => '<i></i> <i class="icon-chevron-left"></i>', 'next_text' => '<i class="icon-chevron-right"></i> <i></i>', 'add_args' => false, 'add_fragment' => '', ] );
wo wir verwenden:
$current = max( 1, (int) filter_input( INPUT_GET, 'p-page' ) );
,das auchin das Argument
eingehtWP_Query
von$query
:'paged' => $current,
Beispielausgabefür
?p-page=6
:<a class="prev page-numbers" href="?p-page=5"><i></i> <i class="icon-chevron-left"></i></a> <a class='page-numbers' href=''>1</a> <a class='page-numbers' href='?p-page=2'>2</a> <span class="page-numbers dots">…</span> <a class='page-numbers' href='?p-page=5'>5</a> <span class='page-numbers current'>6</span> <a class='page-numbers' href='?p-page=7'>7</a> <span class="page-numbers dots">…</span> <a class='page-numbers' href='?p-page=99'>99</a> <a class='page-numbers' href='?p-page=100'>100</a> <a class="next page-numbers" href="?p-page=7"><i class="icon-chevron-right"></i> <i></i></a>
ps:
sprintf
mussnicht zwei statische Zeichenfolgen kombinieren,wie wirim OPfürprev_text
undnext_text
sehen. Derzeit sieht dieser Teilim Original-Snippetfalsch aus,daher habeichihnentfernt.
Hoffees hilft!
This part:
'base' => str_replace( 999999999, '%#%', esc_url( get_pagenum_link( 999999999 ) ) ),
is generating a
page
part like this one:'base' => http://example.tld/page/%#%/
If we peek into
paginate_links()
we see the default:'base' => $pagenum_link, // http://example.com/all_posts.php%_% : // %_% is replaced by format (below) 'format' => $format, // ?page=%#% : %#% is replaced by the page number
where the inline comment say that
%_%
is replaced by the format.The documentation also says:
An example of the
‘base’
argument is"http://example.com/all_posts.php%_%"
and the‘%_%’
is required. The‘%_%’
will be replaced by the contents of in the‘format’
argument. An example for the‘format’
argument is"?page=%#%"
and the ‘%#%’ is also required. The‘%#%’
will be replaced with the page number.If we use that:
'base' => '%_%'
then it will become the same as the
format
argument.Here's a modification of OP's example:
echo paginate_links( [ 'base' => '%_%', 'total' => $query->max_num_pages, 'current' => $current, 'format' => '?p-page=%#%', 'show_all' => false, 'type' => 'plain', 'end_size' => 2, 'mid_size' => 1, 'prev_next' => true, 'prev_text' => '<i></i> <i class="icon-chevron-left"></i>', 'next_text' => '<i class="icon-chevron-right"></i> <i></i>', 'add_args' => false, 'add_fragment' => '', ] );
where we use:
$current = max( 1, (int) filter_input( INPUT_GET, 'p-page' ) );
that will also go into the
WP_Query
argument of$query
:'paged' => $current,
Example output for
?p-page=6
:<a class="prev page-numbers" href="?p-page=5"><i></i> <i class="icon-chevron-left"></i></a> <a class='page-numbers' href=''>1</a> <a class='page-numbers' href='?p-page=2'>2</a> <span class="page-numbers dots">…</span> <a class='page-numbers' href='?p-page=5'>5</a> <span class='page-numbers current'>6</span> <a class='page-numbers' href='?p-page=7'>7</a> <span class="page-numbers dots">…</span> <a class='page-numbers' href='?p-page=99'>99</a> <a class='page-numbers' href='?p-page=100'>100</a> <a class="next page-numbers" href="?p-page=7"><i class="icon-chevron-right"></i> <i></i></a>
ps: There's no need for
sprintf
to combine two static strings, as we see in the OP forprev_text
andnext_text
. Currently that part looks wrong in the original snippet, so I removed it.
Hope it helps!
-
Ich habegeholfen,vielen Dank.Nureine letzte Frage zum Paging: Wie kannichjedem Link data-page="{the-page}" hinzufügen?Ich checkein https://codex.wordpress.org/Function_Reference/paginate_linksein,kann aber keinen WegfindenId did help, thank you so much. Just one last question about the paging, how could i add to every link data-page="{the-page}" ? I'm checking in https://codex.wordpress.org/Function_Reference/paginate_links but cant find a way
- 0
- 2017-08-17
- Toni Michel Caubet
-
Ichbin froh zu hören,dassesgeholfen hat.Dafürgibt es keineexpliziten Filter (nur den Filterpaginate_links,um das href-Attributjedes Tags zu ändern),sodass Siemöglicherweise versuchen,mit preg_replace ()in der Ausgabe zu spielen.Für umfangreiche Änderungenistesmöglicherweisebesser,eine benutzerdefinierte Funktion zu verwenden,die aufpaginate_links ()basiert.Glad to hear it helped. There are no explicit filters for that, (just the paginate_links filter to modify the href attribute of each a tag) so you might try to play with preg_replace() on the output. For extensive modifications, it might be better to use a custom function, based on paginate_links().
- 0
- 2017-08-17
- birgire
Ichbrauche die Paginierungslikes,um die URL zu haben,wie:
Und so .. Der Grund,warumich dasbrauche,ist,dassich andere Parameter auf der Seite habe.
Das Problemist,dassin den Dokumenten Folgendes angegebenist:
format
Undich habeeine freundliche URL aktiviert,
Wie kannich die Standardeinstellung verhindern (Übrigensignoriert siemeine
p-page
und verwendet weiterhinpage
)Diesistmomentanmein Code:
Als vorübergehende Lösungmacheich das so:
Aber wäreestoll,die Punktfunktionalität zunutzen und so ..irgendeine Idee?