Jolis permaliens paginés dans une boucle de type de publication personnalisée
1 réponses
- votes
-
- 2011-02-16
Lorsque vous utilisez
paged
sur un seul article,il recherche un articlepaginé,pas despages d'articles. Étant donné que vos sujetsn'ontpas de contenupaginé,cela suppose que c'est uneerreuret que vous redirigez vers la ``première ''page du sujet,bien avant que votrebouclepersonnaliséene soittouchée. Donc,dans ce cas,paged
vatoujours revenir comme 1. Pour contourner leproblème,j'enregistrerais un Permalien EPpour le sujet. Quelque chose comme ça:add_rewrite_endpoint( 'tpage', EP_PERMALINK );
Ensuite,au lieu de vérifier
get_query_var( 'paged' );
,vérifiezget_query_var( 'tpage' );
et transmettez la valeurpour cela au client requete. La configuration de cepoint determinaison de réécriture signifie quetous lespermaliens compatibles avec lemasque debitsEP_PERMALINK
(vos sujets sont compatibles) accepteront une structure/tpage/XXXX
ajoutée à lafin de l'url,où XXXXXpeut êtretout ce que vous voulez (dans ce cas,vous voudrez letyper comme unentier,probablement absoluen plus).MODIFIER
Quelque chose comme ça devraitfonctionnerpour vous obtenir untableau de lienspaginés:
$links = paginate_links(array( 'base' => trailingslashit( get_permalink( $temp->post->ID ) ) . '%_%', 'format' => 'tpage/%#%', 'type' => 'array' ));
Àpartir de là,vouspouvezfaire quelque chose comme ceci:
<div class="page-navi clear-block"> <?php foreach( $links as $link ){ if( false !== strpos( $link, " class='page-numbers'" ) ) $link = str_replace( " class='page-numbers'", " class='page page-numbers'", $link ); echo $link; } ?> </div>
Je suis àpeuprès sûr que vous obtiendriez lesmêmes styleset le style "actuel"pour les liens.
When you use
paged
on a single post, it's checking for a paginated post, not pages of posts. Because your topics don't have paginated content, it's assuming it's a mistake and redirecting to the 'first' page of the topic, long before your custom loop is ever touched. So, in this instance,paged
is always going to return as 1. As a workaround, I'd register an EP Permalink for the topic. Something like this:add_rewrite_endpoint( 'tpage', EP_PERMALINK );
Then, instead of checking for
get_query_var( 'paged' );
, check forget_query_var( 'tpage' );
and pass the value for that along to the custom query. Setting up that rewrite endpoint means that all permalinks compatible with theEP_PERMALINK
bitmask (your topics are compatible) will accept a/tpage/XXXX
structure added to the end of the url, where XXXXX can be anything you want (in this instance, you'd want to typecast it as an integer, probably an absolute one at that).EDIT
Something like this should work to get you an array of paginated links:
$links = paginate_links(array( 'base' => trailingslashit( get_permalink( $temp->post->ID ) ) . '%_%', 'format' => 'tpage/%#%', 'type' => 'array' ));
From there, you could do something like this:
<div class="page-navi clear-block"> <?php foreach( $links as $link ){ if( false !== strpos( $link, " class='page-numbers'" ) ) $link = str_replace( " class='page-numbers'", " class='page page-numbers'", $link ); echo $link; } ?> </div>
I'm pretty sure that'd get you the same styles and the 'current' style for the links.
-
sympa,çamarche :) la seule choseest quej'aibesoin de créermaproprefonction depagination,car wp_page_navi vérifie `page`.Mercinice, it works :) the only thing is that I need to make my own paging function, because wp_page_navi checks for `page`. thanks
- 0
- 2011-02-16
- onetrickpony
-
avez-vousjeté un œil à `paginate_links ()`?J'ai écrit à ce sujet surmonblogici: http://jbl.me/2hhave you had a look at `paginate_links()`? I wrote about it on my blog here: http://jbl.me/2h
- 0
- 2011-02-16
- John P Bloch
-
J'aiessayé l'exempleici: http://codex.wordpress.org/Function_Reference/paginate_links (pagemodifiée/paginée avectpage),et j'obtiens des liens comme `.../tpage/2/tpage/2`,et même siJe change lapagemanuellement,lapage actuellen'estpas considérée comme active ...I tried the example here: http://codex.wordpress.org/Function_Reference/paginate_links (changed page/paged with tpage), and I get links like `.../tpage/2/tpage/2`, and even if I change the page manually the current page is not seen as active...
- 0
- 2011-02-16
- onetrickpony
-
remplacer `get_pagenum_link (1)`par `get_permalink ()` corrige les liens,maisj'obtienstoujours la 1èrepage comme active,quelle que soit lapage sur laquelleje suis actuellementreplacing `get_pagenum_link(1)` with `get_permalink()` fixes the links, but I still get the 1st page as active, regardless of what page I'm actually on
- 0
- 2011-02-16
- onetrickpony
-
corrigéen passant leparamètre actuel demafonction deboucle.Je suppose que cela a quelque chose à voir avec le désordre de la variableglobale ...fixed by passing the current parameter from my loop function. I guess it has something to do with the global variable mess...
- 0
- 2011-02-16
- onetrickpony
-
J'ai ajouté unpeu de code qui utiliserait `paginate_links`et devraitfairefonctionner lapage 'active'.I added a bit of code that would use `paginate_links` and should get the 'active' page working.
- 0
- 2011-02-16
- John P Bloch
Je dois vousennuyer avectoutes ces questions depermalien :)
Le code quej'utilisepour laboucleest:
Lapaginationfonctionnebien si lespermaliens sont définispar défaut,lorsque vous cliquez sur le lien de lapage 2,l'URL quej'obtiensest comme:
http://localhost/wp/?topic=sometopictitle&paged=2
Leproblème survient lorsqueje place lespermaliens sur une structurepersonnalisée;en cliquant sur lapage 2,j'obtiens l'URL de lapremièrepage:
http://localhost/wp3/forum/general-discussion/topic/sometopictitle/
au lieu de
http://localhost/wp3/forum/general-discussion/topic/sometopictitle/page/2/
(Unexempleen direct
ici
)Quelqu'un connaît-il les règles queje devrais ajouterpour définir lespermalienspaginéspour letype demessage "topic-reply"?