Récupère le slug du terme du message actuel
2 réponses
- votes
-
- 2014-01-23
Votre codefonctionne sur unepage où untermeestinterrogé (une archive determes detaxonomie),pas un seul article.
Pour un seulmessage,vous devez récupérer lestermes appartenant à cemessage.
$terms = get_the_terms( $post->ID, 'your-taxonomy' ); if ( !empty( $terms ) ){ // get the first term $term = array_shift( $terms ); echo $term->slug; }
Your code works on a page where a term is queried (a taxonomy term archive), not a single post.
For a single post, you need to fetch the terms belonging to that post.
$terms = get_the_terms( $post->ID, 'your-taxonomy' ); if ( !empty( $terms ) ){ // get the first term $term = array_shift( $terms ); echo $term->slug; }
-
Merci!Ne comprendpasexactement ce que vousfaitesmais celafonctionne.Thanks! Doesn't understand exactly what you are doing but it works.
- 0
- 2014-01-24
- Robbert
-
Solutionincroyable!J'aiessayé d'utiliser la documentationpour obtenirtous lestermesmaispas de dés.Connaissez-vous unmoyen defaire cela?http://codex.wordpress.org/Function_Reference/get_termAmazing solution! I tried to use documentation to get all the terms but no dice. Do you know a way to do that? http://codex.wordpress.org/Function_Reference/get_term
- 0
- 2015-03-02
- GuiHarrison
-
@GuiHarrison Àmon avis,alors vous devez laisser array_shift ()et parcourir letableau $term.@GuiHarrison In my opinion then you need to leave array_shift() away, and loop through the $term array.
- 0
- 2015-05-06
- Robbert
-
- 2016-01-31
Le code ci-dessousfonctionnebien s'il y aplusieurstermes à afficher.:-
echo get_the_term_list( $post->ID, 'styles', '<ul class="styles"><li>', ',</li><li>', '</li></ul>' );
Below code works well if have multiple terms to show.:-
echo get_the_term_list( $post->ID, 'styles', '<ul class="styles"><li>', ',</li><li>', '</li></ul>' );
Jetravaille sur unmodèle detype d'article unique oùj'affiche unmenu denavigation avec des liens verstous les articles dumêmeterme.
Maintenant,je veux utiliser cemodèlepourtous les différentstermes,donc $term_slug doit contenir leterme slug dumessage actuel afin qu'ilpuisse correspondre aux autresmessages.
J'aitrouvéplusieursfois sur Internet ce codepourfaire letravail,mais celane fonctionnepaspourmoi:
Cet article dit que celaferait l'affaire: http://www.wpbeginner.com/wp-themes/how-to-show-the-current-taxonomy-title-url-and-more-in-wordpress/
Qu'est-ce queje fais demal?