Comment puis-je créer un lien "Lire la suite" en utilisant the_excerpt () sur une page d'accueil statique?
-
-
quelest le code dumodèle depage?what is the code of the page template?
- 0
- 2014-02-11
- Michael
-
J'ai ajouté ** unepartie ** du code de lapage demodèle (lebit pertinent).Si vous voulez voir letout,je peux leposter ...mais c'est unpeu long.I've added **some** of the code from the template page (the relevant bit). If you want to see the whole thing, I can post it... but it's kinda long.
- 0
- 2014-02-11
- convoke
-
1 réponses
- votes
-
- 2014-02-11
lorsque vous remplissez la zone Extrait avec dutexte sur lapage demodification de l'article,lafonction
the_excerpt()
n'ajoutepas de lireplus ou ... à lafin de labrève description. Lire la suite n'estinclus que si Extrait est vide,et cen'estpas unbogue,c'est unefonctionnalité.Désormais,la solutionest d'éviter lefiltre
excerpt_more
pour renvoyer readmore,et d'utiliser le hookthe_excerpt
. Maisexcerpt_more
doit être défini comme videpour s'assurer que le double readmoren'estpas affiché. Donc,le code dont vous avezbesoin -function new_excerpt_more($more) { return ''; } add_filter('excerpt_more', 'new_excerpt_more', 21 ); function the_excerpt_more_link( $excerpt ){ $post = get_post(); $excerpt .= '... <a href="'. get_permalink($post->ID) . '">continue reading</a>.'; return $excerpt; } add_filter( 'the_excerpt', 'the_excerpt_more_link', 21 );
Le code ci-dessuspourrait aller dans lefichierfunctions.php de vosthèmes.
when you fill the Excerpt box with any text on post edit page,
the_excerpt()
function doesn't add any read more or ... at the end of the short description. Read more is only included if Excerpt is set empty, and this is not a bug, it's a feature.Now the solution is to avoid the
excerpt_more
filter to return read more, and use thethe_excerpt
hook. Butexcerpt_more
should be set the empty to make sure double read more is not displayed. So, the code you need -function new_excerpt_more($more) { return ''; } add_filter('excerpt_more', 'new_excerpt_more', 21 ); function the_excerpt_more_link( $excerpt ){ $post = get_post(); $excerpt .= '... <a href="'. get_permalink($post->ID) . '">continue reading</a>.'; return $excerpt; } add_filter( 'the_excerpt', 'the_excerpt_more_link', 21 );
Above code could go to your themes functions.php file.
-
Jen'ai rien ajouté au champ detexte Extrait dumessage,et jen'aipas l'intention de lefaire.Commeje l'ai dit,l'idéeest de rendre les choses aussi simples quepossiblepour le client.Le code actuel **tronque ** lemessage à 55mots,ou quelle que soit la valeurpar défaut,et ajoute lespoints de suspension.Leproblèmeest quemaméthodenormalepourtransformer cespoints de suspensionen un lien «Lire la suite»ne semblepasfonctionner.I haven't added anything to the Excerpt text field on the post, nor do I intend to. Like I said, the idea is to make things as low maintenance as possible for the client. The current code **does** truncate the post to 55 words, or whatever the default is, and adds the ellipsis. The problem is that my normal method for turning that ellipsis into a "Read More" link doesn't seem to be working.
- 0
- 2014-02-11
- convoke
-
Donc,j'aiessayé votre codeet cela semblefonctionner.Le seulproblèmeest quej'obtiens une doubleellipse.C'esten direct sur http://stuandjessproductions.comen cemoment,si vous voulez voir.Avez-vous desidées?So, I tried your code, and it seems to work. Only problem is, I get a double ellipsis. It's live on http://stuandjessproductions.com right now, if you want to see. Do you have any ideas?
- 0
- 2014-02-11
- convoke
-
Je dois ajouter quej'ai ** supprimé **mon code d'origine defunctions.php.I should add that I **removed** my original code from functions.php.
- 0
- 2014-02-11
- convoke
-
J'aimarqué cette question comme une réponse,mais la solutionestjusqu'àinjecter deuxbalises "en savoirplus".Je viens de supprimer lespoints de suspension de la deuxièmebalise,ce quifonctionnepourmoi,mais cen'estpas vraimentparfait.I marked this question as an answer, but the solution is till injecting two "read more" tags. I just removed the ellipsis from the second tag, which works for me, but it's not really perfect.
- 0
- 2014-02-13
- convoke
-
Essayez le codemis àjour.Try the updated code.
- 0
- 2014-02-13
- Shazzad
-
Pourquoien avons-nous ajouté 21?Why we have added 21 in it?
- 0
- 2018-04-11
- Navnish Bhardwaj
-
@NavnishBhardwaj - 21est lapriorité dufiltreici.Là,vouspouvez vousn'importe quelnombrepositif supérieur à 0.@NavnishBhardwaj - 21 is the filter priority here. There you can you any positive number more than 0.
- 1
- 2018-04-11
- Shazzad
-
Merci @Shazzad.Après avoirbeaucoup cherché,j'aifinalement compris comment Read Morefonctionne avec Extrait.Thanks @Shazzad. After searching a lot, finally I understood how Read More works with Excerpt.
- 0
- 2020-06-10
- Pooja Mistry
Jetravaille sur un site Web qui utilise unepage d'accueil statique. Ilmontre également lebillet deblog leplus récent. Ceci a été réaliséen créant unepageet en utilisant unmodèle depagepersonnalisé.
Parfois,lebillet deblogesttrop long,je veux donc utiliserthe_excerptpour le raccourcir automatiquement sans avoirbesoin d'unebalise supplémentaire.
Jusqu'icitout vabien. Mais,the_excerptne créepas réellement de lien "en savoirplus". C'est unproblème assez courant,j'ai donc ajouté:
dansmonfichierfunctions.php.
J'aien fait utilisé ce code sansproblème sur un autre site,maispour une raison quelconque,celane fonctionnepas dans ce cas. Mapremièreestimation était que c'étaitparce qu'il était appelé sur unepage statique.
Le site Webest http://stuandjessproductions.com . Lethèmeest Central de QODEet j'utilise unthèmeenfantpersonnalisé.
Ajout de code àpartir de lapagemodèle,conformément à la demande. Cen'estpas lapageentière,maisplutôtjuste l'élémentpertinentpour lemessage d'actualité: