Comment obtenir le terme actuel dans ma taxonomie personnalisée dans WordPress?
6 réponses
- votes
-
- 2011-02-15
Vouspouvez utiliser
get_the_term_list()
:Description
Renvoie une chaîne HTML determes detaxonomie associés à un articleet à unetaxonomie donnée.Lestermes sont liés à leurspages de liste determes respectives.
Utilisation
<?php get_the_term_list( $id, $taxonomy, $before, $sep, $after ) ?>
You can use
get_the_term_list()
:Description
Returns an HTML string of taxonomy terms associated with a post and given taxonomy. Terms are linked to their respective term listing pages.
Usage
<?php get_the_term_list( $id, $taxonomy, $before, $sep, $after ) ?>
-
le seulproblème avecget_the_term_listest qu'ilenveloppe lestermesen html.utilisez wp_get_object_terms ()pour récupérer untableau determesthe only problem with get_the_term_list is that it wraps the terms in html. use wp_get_object_terms() to get an array of terms back
- 1
- 2011-02-15
- anu
-
Dans ce cas,vouspouvez utiliser `get_the_terms` à laplace.In that case you could use `get_the_terms` instead.
- 0
- 2011-02-15
- t31os
-
- 2011-02-16
réservoirs de réponse demon ami,je letrouvepourmontrer le slug demataxonomie
<?php $terms = get_terms('my-taxonomy-name'); foreach ( $terms as $term ) { echo $term->slug.' '; } ?>
et maisil renvoietous lestermes demataxonomieet je dois renvoyer leterme courant dansmataxonomie ..
MISE À JOUR:
Jetrouvefinalement ceciet ajoute sipour lestermes videset fonctionne
<?php // Get terms for post $terms = get_the_terms( $post->ID , 'oil' ); // Loop over each item since it's an array if ( $terms != null ){ foreach( $terms as $term ) { // Print the name method from $term which is an OBJECT print $term->slug ; // Get rid of the other data stored in the object, since it's not needed unset($term); } } ?>
tanks for answer from my friend , i find it for show slug of my taxonomy
<?php $terms = get_terms('my-taxonomy-name'); foreach ( $terms as $term ) { echo $term->slug.' '; } ?>
and but it return all term in my taxonomy and i need to return current term in my taxonomy ..
UPDATE :
i finaly find this and add if for empty terms and works
<?php // Get terms for post $terms = get_the_terms( $post->ID , 'oil' ); // Loop over each item since it's an array if ( $terms != null ){ foreach( $terms as $term ) { // Print the name method from $term which is an OBJECT print $term->slug ; // Get rid of the other data stored in the object, since it's not needed unset($term); } } ?>
-
- 2011-02-15
Je l'aitrouvé:
<?php //list terms in a given taxonomy using wp_list_categories (also useful as a widget if using a PHP Code plugin) $taxonomy = 'genre'; $orderby = 'name'; $show_count = 0; // 1 for yes, 0 for no $pad_counts = 0; // 1 for yes, 0 for no $hierarchical = 1; // 1 for yes, 0 for no $title = ''; $args = array( 'taxonomy' => $taxonomy, 'orderby' => $orderby, 'show_count' => $show_count, 'pad_counts' => $pad_counts, 'hierarchical' => $hierarchical, 'title_li' => $title ); ?> <ul> <?php wp_list_categories( $args ); ?> </ul>
Il obtienttous lestermes demataxonomiepersonnaliséeet je dois obtenir leterme actuel.
I found it:
<?php //list terms in a given taxonomy using wp_list_categories (also useful as a widget if using a PHP Code plugin) $taxonomy = 'genre'; $orderby = 'name'; $show_count = 0; // 1 for yes, 0 for no $pad_counts = 0; // 1 for yes, 0 for no $hierarchical = 1; // 1 for yes, 0 for no $title = ''; $args = array( 'taxonomy' => $taxonomy, 'orderby' => $orderby, 'show_count' => $show_count, 'pad_counts' => $pad_counts, 'hierarchical' => $hierarchical, 'title_li' => $title ); ?> <ul> <?php wp_list_categories( $args ); ?> </ul>
It gets all terms in my custom taxonomy and I need to get current term.
-
Pour vosimages,vous devez utiliser despseudo sélecteurs CSSpourinjecter vosicônes.For your images, you should use CSS pseudo selectors to inject your icons.
- 0
- 2011-09-21
- Brian Fegter
-
- 2011-02-15
Vous devez utiliser
wp_get_object_terms()
wp_get_object_terms( $object_ids, $taxonomies, $args )
- $ object_ids:identifiants de chaîne ou detableaupour les objetspour lesquels vous souhaitez obtenir destermes
- $taxonomies: chaîne outableau detaxonomies
You need to use
wp_get_object_terms()
wp_get_object_terms( $object_ids, $taxonomies, $args )
- $object_ids: string or array ids for the objects you want to get terms for
- $taxonomies: string or array of taxonomies
-
-
- 2016-10-28
Enprenant ce que user3208 a codé,j'ai ajouté unpeu de code qui ajoute l'URL auterme.J'espère que cela aide quelqu'un.
<?php // Get terms for post $terms = get_the_terms( $post->ID , 'oil' ); // Loop over each item since it's an array if ( $terms != null ){ foreach( $terms as $term ) { $term_link = get_term_link( $term, 'oil' ); // Print the name and URL echo '<a href="' . $term_link . '">' . $term->name . '</a>'; // Get rid of the other data stored in the object, since it's not needed unset($term); } } ?>
Taking what user3208 coded, I have added a bit of code that adds the URL to the Term. Hope that helps someone out.
<?php // Get terms for post $terms = get_the_terms( $post->ID , 'oil' ); // Loop over each item since it's an array if ( $terms != null ){ foreach( $terms as $term ) { $term_link = get_term_link( $term, 'oil' ); // Print the name and URL echo '<a href="' . $term_link . '">' . $term->name . '</a>'; // Get rid of the other data stored in the object, since it's not needed unset($term); } } ?>
Je dois afficher leterme actuel dansmataxonomiepersonnalisée dans un seul article.
Enfait,j'aibesoin d'unefonction comme
the_category();
de WordPressmaispourmataxonomie commethe_customtaxonomy();
MISE À JOUR:
en fait,je sais quej'aibesoin d'obtenir l'identifiant de ce carje dois afficher uneicônepour cela dansmon single,parexemple unefonction comme
the_category_ID();