get_the_term_list sans liens dans 3.1
5 réponses
- votes
-
- 2011-02-01
wp_get_object_terms () renvoie lestermes associés à un objet (parexemple,un article ou unepage ou un articlepersonnalisé) sousforme detexte (normalement dans untableau).
Depuis lapage Codexpour wp_get_object_terms ()
$productcategories = wp_get_object_terms($post->ID, 'productcategories');
wp_get_object_terms() returns the terms associated with an object (eg a post or a page or custom post) as text (normally in an array).
From the Codex page for wp_get_object_terms()
$productcategories = wp_get_object_terms($post->ID, 'productcategories');
-
Gardez à l'esprit que les résultats de la requêtene sontpasmisen cache comme `get_the_terms ()`.Voir la [page de codex] (https://codex.wordpress.org/Function_Reference/wp_get_object_terms)pourplus d'informations.Keep in mind that the query results aren't cached like `get_the_terms()`. See the [codex page](https://codex.wordpress.org/Function_Reference/wp_get_object_terms) for info.
- 0
- 2016-09-08
- Dylan
-
- 2011-02-01
Cependant @anu a raison,j'ai compris que vouspouviez appeler lafonctionphp strip_tags pour supprimer lesbalises de la valeur de retour.
$terms = get_the_term_list( $post->ID, 'tags' ); $terms = strip_tags( $terms );
However @anu is right, I figured out you can call the php function strip_tags to strip out the tags of the return value.
$terms = get_the_term_list( $post->ID, 'tags' ); $terms = strip_tags( $terms );
-
Cela a l'air si simpleet fait letravail.Y a-t-il uninconvénient à l'utiliser?Looks so simple and does the job. Is there any downside using this?
- 0
- 2017-01-03
- Mohsin
-
@Mohsin Uninconvénientest qu'il supprimetoutes lesbalises,pas seulement labalise .Cependant,vouspouvezempêcher la suppression desbalises souhaitées,comme ceci: `$terms=strip_tags ($terms,'
- ');`
@Mohsin One downside is that it strips all tags, not just the tag. However, you can prevent desired tags from being stripped, like so: `$terms = strip_tags( $terms, '- ' );`
- 0
- 2017-12-06
- David
-
- 2011-02-01
get_the_terms_list ()estimplémentéici: http://core.trac.wordpress.org/browser/tags/3.0.4/wp-includes/category-template.php # L948 .
$term_links = apply_filters( "term_links-$taxonomy", $term_links );
Vouspouvezmettreen œuvre votreproprefiltre.
I think the best way is to implement a filter for the term list, that extract via regexp only the text, from the list
get_the_terms_list() is implemented here: http://core.trac.wordpress.org/browser/tags/3.0.4/wp-includes/category-template.php#L948.
$term_links = apply_filters( "term_links-$taxonomy", $term_links );
You can implement you own filter.
-
- 2019-07-05
$terms = wp_list_pluck( get_the_terms( get_the_ID(), 'your_taxonomy' ), 'name');
Ici,$termsest untableau,vouspouvez donc utiliser uneboucleforeach.
foreach( $terms as $term ) { echo $term; }
$terms = wp_list_pluck( get_the_terms( get_the_ID(), 'your_taxonomy' ), 'name');
Here $terms is an array, so you can use a foreach loop.
foreach( $terms as $term ) { echo $term; }
-
- 2013-01-17
J'aibesoin de lamême solutionet j'aiessayé la solution Zack quifonctionnetrèsbien.Parexemple,si vousn'avezbesoin que duterme àmettre dans l'identifiant ou la classe css. Une seule remarque sur la solution,lafonctionestmal appelée,est correctement "get_the_term_list".
Jemontremonexemple:
$terms = get_the_term_list( $post->ID, 'your_taxonomy_name' ); $terms = strip_tags( $terms );
I need the same and tried Zack solution that works great. For instance, if you need onlye the term to put in css id or class. Only one anotation about the solution, the function is bad called, properly is "get_the_term_list".
I show my example:
$terms = get_the_term_list( $post->ID, 'your_taxonomy_name' ); $terms = strip_tags( $terms );
Quellefonction affichera lestaxonomiespersonnalisées associées à un article sousforme detexte?
J'utilise actuellementget_the_term_list quifonctionnetrèsbien pour unepage singulière,maispastellement lorsquej'utilise unetaxonomie dans labalise detitre depermalien archive-postype.php.