Comment obtenir le nom actuel de get_post_types?
2 réponses
- votes
-
- 2014-11-25
Vous aurezbesoin d'unemanière ou d'une autre de l'objet depublication,ou de l'objetinterrogé sur les archives detype depublication.Sur une seulepage,vouspourriezfaire:
$post = get_queried_object(); $postType = get_post_type_object(get_post_type($post)); if ($postType) { echo esc_html($postType->labels->singular_name); }
Ou dans laboucle:
$postType = get_post_type_object(get_post_type()); if ($postType) { echo esc_html($postType->labels->singular_name); }
Dans les archives destypes d'articles:
$postType = get_queried_object(); echo esc_html($postType->labels->singular_name);
Tous ces éléments vous donneront lenom singulier dutype depublication qui a étéenregistré dans la clé
register_post_type
labels
.You'll need the post object somehow, or, alternatively the queried object on post type archives. On a singular page you might do:
$post = get_queried_object(); $postType = get_post_type_object(get_post_type($post)); if ($postType) { echo esc_html($postType->labels->singular_name); }
Or in the loop:
$postType = get_post_type_object(get_post_type()); if ($postType) { echo esc_html($postType->labels->singular_name); }
In post type archives:
$postType = get_queried_object(); echo esc_html($postType->labels->singular_name);
All of these will give you the singular name of the post type that was registered in
register_post_type
'slabels
key.-
Pouvez-vousm'aiderici.J'utilisemaintenant le code suivant: http://snippi.com/s/wookr64 Avec ce code,je veux appeler uniquement lesposttypes actuels sur lapage.Maintenant,celane fonctionnepas correctement.Qu'est-ce queje metrompe?Can you help me here. I use the following code now: http://snippi.com/s/wookr64 With this code I want to call only the current posttypes on the page. Now it doesn’t work correctly. What does I wrong?
- 0
- 2014-11-25
- Casper
-
@Casper Jepense que vous devrezfaire,aller vous asseoiret reconstruire votre questionprécédente.Ce que vous voulezn'esttoujourspas clair.Pourquoi [cette réponse sur SO] (http://stackoverflow.com/a/27137675/1908141)n'a-t-ellepasfonctionné.Expliquez avec desexempleset desnoms demodèlesexactement ce que vous voulez.Je vous remercie@Casper I think what you will need to do, go and sit down, and reconstruct your previous question. It is still totally unclear what you want. Why did [this answer on SO](http://stackoverflow.com/a/27137675/1908141) not work. Explain with examples and template names exactly what you want. Thank you
- 2
- 2014-11-26
- Pieter Goosen
-
- 2017-01-23
Pour obtenir lenom dutype depublication actuel,utilisez le code suivant dans laboucle.
$post_type = get_post_type( get_the_ID() ); echo '<p>' . $post_type . '</p>';
ou afficher lenom dutype depublication à l'aide de lafonctionprintf.
printf( __( 'The post type is: %s', 'textdomain' ), get_post_type( get_the_ID() ) );
To get the name of the current post type, use the following code inside the loop.
$post_type = get_post_type( get_the_ID() ); echo '<p>' . $post_type . '</p>';
or display the post type name using printf function.
printf( __( 'The post type is: %s', 'textdomain' ), get_post_type( get_the_ID() ) );
Commentpuis-je obtenir lenom dutype depublicationpersonnalisé actuelet lemettreen écho sur unepage?