paginate_links ignore mon format
1 réponses
- votes
-
- 2017-08-16
Cettepartie:
'base' => str_replace( 999999999, '%#%', esc_url( get_pagenum_link( 999999999 ) ) ),
génère unepartie
page
comme celle-ci:'base' => http://example.tld/page/%#%/
Sinousjetons un œil à
paginate_links()
nous voyons la valeurpar défaut:'base' => $pagenum_link, // http://example.com/all_posts.php%_% : // %_% is replaced by format (below) 'format' => $format, // ?page=%#% : %#% is replaced by the page number
où le commentaireen ligneindique que
%_%
est remplacépar leformat.La documentation dit également:
Unexemple de l'argument
‘base’
est"http://example.com/all_posts.php%_%"
et le‘%_%’
sont obligatoires. le‘%_%’
sera remplacépar le contenu de l’argument‘format’
. Un exemplepour l'argument‘format’
est"?page=%#%"
et le ‘% #%’est également obligatoire. Le‘%#%’
sera remplacépar lenuméro depage.Sinous utilisons cela:
'base' => '%_%'
alorsil deviendra lemême que l'argument
format
.Voici unemodification de l'exemple d'OP:
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' => '', ] );
oùnous utilisons:
$current = max( 1, (int) filter_input( INPUT_GET, 'p-page' ) );
quiira également dans l'argument
WP_Query
de$query
:'paged' => $current,
Exemple de sortiepour
?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: Iln'estpasnécessaire que
sprintf
combine deux chaînes statiques,commenous le voyons dans l'OPpourprev_text
etnext_text
. Actuellement,cettepartiene semblepas correcte dans l'extrait d'origine,je l'ai donc supprimée.
J'espère que cela aide!
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!
-
J'avais aidé,mercibeaucoup.Juste une dernière question sur lapagination,commentpuis-je ajouter à chaque lien data-page="{the-page}"?Je vérifie https://codex.wordpress.org/Function_Reference/paginate_linksmaisje netrouvepas demoyenId 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
-
Heureux de l'entendre aidé.Iln'y apas defiltresexplicitespour cela (juste lefiltrepaginate_linkspourmodifier l'attribut href de chaquebalise a) donc vouspouvezessayer dejouer avecpreg_replace () sur la sortie.Pour desmodificationsimportantes,ilpeut êtrepréférable d'utiliser unefonctionpersonnalisée,basée surpaginate_links ().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
J'aibesoin des liks depaginationpour avoir l'URL,comme:
Et donc ... La raisonpour laquellej'en aibesoinestparce quej'ai d'autresparamètres dans lapage.
leproblèmeest que dans la documentation,il spécifie:
Etj'ai activé les URL conviviales,
Commentpuis-jeempêcher la valeurpar défaut (BTW,ilignorema
p-page
,toujoursen utilisantpage
)voicimon code,en cemoment:
Entant que solutiontemporaire,je lefais comme ceci:
Mais serait-ilgénial deprofiter de lafonctionnalité despointset donc .. uneidée?