obtenir l'url / lien de l'archive des termes
6 réponses
- votes
-
- 2012-04-09
Utilisez
get_term_link
parexemplepourimprimer une liste determes d'acteurs renvoyant aux archives:
$terms = get_terms('actors'); echo '<ul>'; foreach ($terms as $term) { echo '<li><a href="'.get_term_link($term).'">'.$term->name.'</a></li>'; } echo '</ul>';
Cependant!
Si ce que vous voulez vraiment direest l'équivalent de l'archive detype depublicationpersonnalisée,qui répertorietous lesmessages de cetype,maispour lestermes detaxonomie,parexemple unepage qui agit comme une archive répertoriant les différentstermes detaxonomie disponibles,alors vousn'avezpas de chance. Iln'y apas d'archives detaxonomie dans WordPresspour lestermes,uniquement les articles attribués à unterme donné.
Pourproduire unepage répertoriant lestermes detaxonomie,vouspouvez utiliser un code similaire à celui ci-dessus. Ensuite,placez-le dans unmodèle depageet utilisez cettepage comme archive determes detaxonomie.
La raisonen est que leproblème réside dans laboucle depublication,presque chaquemodèle depageest destiné àen avoir un,et si vous regardez la hiérarchie desmodèles,si lesmodèlesnécessairesne sontpastrouvés,tout revient àindex.phpet index.php ont uneboucle depublication qui affiche lespublications,pas uneboucle determes. Ceciet lesnombreusesfaçonset idées différentes sur lafaçon dont lestermes doivent être énumérés signifient qu'iln'y apas de consensus. Qu'enest-il des archives de dates? Devrait-il y avoir une archive répertoriant lesmoiset les années? Délais? Panneauxtuilesnuages etc
Use
get_term_link
e.g. to print out a list of actors terms linking to the archives:
$terms = get_terms('actors'); echo '<ul>'; foreach ($terms as $term) { echo '<li><a href="'.get_term_link($term).'">'.$term->name.'</a></li>'; } echo '</ul>';
However!
If what you really mean is the equivilant of the custom post type archive, that lists all the posts of that type, but for taxonomy terms, e.g. a page that acts as an archive listing the various taxonomy terms available, then you're out of luck. There are no taxonomy archives in WordPress for terms, only posts assigned to a given term.
To produce a page listing the taxonomy terms you can use code similar to the above. Then put it in a page template and use that page as your taxonomy term archive.
The reason why is that the problem lies in the post loop, almost every single page template is intended to have one, and if you look at the template heirarchy, if the necessary templates aren't found, it all goes back to index.php, and index.php has a post loop that displays posts, not a term loop. This and the many different ways and ideas of how terms should be listed means there is no consensus. What about date archives? Should there be an archive listing months and years? Timelines? Panels tiles clouds etc
-
Le conseil que vous avez donnéest ce quej'ai recherché.Mon approche était donc d'utiliser unmodèle depage,maisje semble être unemanièretrèspersonnalisée.Mais s'iln'y a aucunepossibilitépour une archive detaxonomie,je dois l'implémenter comme vous l'avez suggéré.MerciThe tip you gave was what i searched for. My approach was so use a page template, but i seems to be a very customized way. But if there are no possibilities for a taxonomy archive i have to implement it like you suggested. thanks
- 0
- 2012-04-10
- mrzmyr
-
Iln'yen apas.Leproblème réside dans laboucle depublication,presque chaquemodèle depageest destiné àen avoir un,et si vous regardez la hiérarchie si lesmodèlesnécessairesne sontpastrouvés,tout revient àindex.php,et index.php a unboucle depublication qui affiche lespublications,pas uneboucle determesThere is none. The problem lies in the post loop, almost every single page template is intended to have one, and if you look at the heirarchy if the necessary templates aren't found, it all goes back to index.php, and index.php has a post loop that displays posts, not a term loop.
- 2
- 2012-04-10
- Tom J Nowell
-
- 2015-08-13
Iln'y apas demoyen simple d'obtenir celaen récurant. Ettout lemonde qui répondpartoutpense que vous voulez créer un lien vers un TERME dans la TAXONOMIE ... Alors que vous cherchez à obtenir un lien vers l'archive TAXONOMIE ... Pour laquelleje n'ai absolument rientrouvé.
Fondamentalement,commebeaucoup degens,vous voulez uneméthode
get_taxonomy_archive_link
.Sauf quepour une raison ou une autre,celan'existetout simplementpas. Je considère cela comme un échec MAJEUR du côté de Wordpress.
Iln'y apas de réponse à votre question. Pas un quifonctionne réellement dans le cadre WP comme une solution appropriée. Bien sûr,vouspouvez assembler
get_bloginfo()
pour vosbesoins,maisiln'y a absolument aucune raison logique dans WP queget_taxonomy_archive_link
n'existepas.Cela étant dit,j'ajoutetoujours lafonction suivante àmesthèmes:
/** * Pass in a taxonomy value that is supported by WP's `get_taxonomy` * and you will get back the url to the archive view. * @param $taxonomy string|int * @return string */ function get_taxonomy_archive_link( $taxonomy ) { $tax = get_taxonomy( $taxonomy ) ; return get_bloginfo( 'url' ) . '/' . $tax->rewrite['slug']; }
There is no simple way to get this from scouring. And everyone who answers everywhere thinks you want to link to a TERM in the TAXONOMY... While you're looking to get a link to the TAXONOMY archive... For which I have found absolutely nothing.
Basically, like many people, you want a
get_taxonomy_archive_link
method.Except, for one reason or another, it simply does not exist. I consider this a MAJOR failure on Wordpress's side.
There is no answer to your question. Not one that actually works within the WP framework as a proper solution. Sure, you can piece together
get_bloginfo()
for your needs, but there is absolutely no logical reason within WP thatget_taxonomy_archive_link
doesn't exist.That all being said, I always add the following function to my themes:
/** * Pass in a taxonomy value that is supported by WP's `get_taxonomy` * and you will get back the url to the archive view. * @param $taxonomy string|int * @return string */ function get_taxonomy_archive_link( $taxonomy ) { $tax = get_taxonomy( $taxonomy ) ; return get_bloginfo( 'url' ) . '/' . $tax->rewrite['slug']; }
-
- 2018-10-08
il semble que vous demandez un lien vers une archive avec "tous lesmessages qui ont unterme de lataxonomie Acteurs" . tout lemondeici a répondu comme si vous demandiez le lien vers une archive determes spécifiques,car ce que vous demandezn'apas de sens dans lemonde wordpress.
Je suis surprispar la réponse depixelbaconet par lefait qu'il a 6 votespositifs ... Cettefonction renvoie une url quine mènenullepart ... wordpressn'apas demoyen d'interpréter cette URLni defaire la requête qui devrait être derrière cette demande.
dans labase de données,unetaxonomie a des relations avec lestermes,et lestermes ont des relations avec lesmessages. Un seul articlen'apas de relations avec lataxonomie. La seule chose qui les relieest lefait qu’unpost-typepourraitprendreen charge unetaxonomie.
Écrivonsen mots ce que vousessayez d'afficher sur cettepage: "Montrez-moitous lesmessages dupost_type 'post',qui contient N'IMPORTE QUELterme de lataxonomie Acteurs."
cela setraduitessentiellementpar: "montre-moitous lesmessages dupost_type 'post' (quiprenden charge lataxonomie Actors)" .
Par conséquent,la seule différencepar rapport à une archivegénérale depost_type (affichertous lesmessages d'unpost_type donné) serait SI vous avez desmessages auxquels aucunterme Acteurn'est attribuéet que vous voulez lesexclure.
Sitelest le cas,vouspouvez créer unepagepersonnalisée,effectuer une requêtegénérique surtous les articles,puis dans laboucle vous vérifiez si l'article contient unterme Acteurs avec
wp_get_post_terms(get_the_ID(), 'actors')
,et éventuellement l'exclure s'iln'en apas.it seems that you're asking for a link to an archive with "all posts which has any term from the taxonomy Actors". everyone here replied as if you asked for the link to a specific term archive because what you're asking doesn't make sense in the wordpress world.
I am surprised by the answer of pixelbacon and the fact that it has 6 upvotes... That function returns an url which leads nowhere... wordpress doesn't have a way to interpret that url nor to make the query which would have to be behind that request.
in the database a Taxonomy has relations with the terms, and the terms have relations with the posts. A single post doesn't have relations with the taxonomy. The only thing that connect them is the fact that a post-type could support a Taxonomy.
Let's write down in words what you're trying to display in that page: "Show me all the posts of the post_type 'post', which has ANY term from the taxonomy Actors."
this basically translate to: "show me all posts of the post_type 'post' (which supports the taxonomy Actors)".
Therefore the only difference from a general post_type archive (show all posts from a given post_type) would be IF you have posts which don't have any Actor term assigned and you DO want to exclude them.
If that's the case, then you can create a custom page, make a generic query to all posts, then in the loop you check if the post has any Actors term with
wp_get_post_terms(get_the_ID(), 'actors')
, and eventually exclude it if doesn't have any. -
- 2012-04-09
Le lien d'archivepourtoutetaxonomie suit cemodèle:
http://{siteurl}/{taxonomy}/{term}
Parexemple,la catégorie "news" sur "myblogsite.com" aurait l'URL d'archive suivante:
http://myblogsite.com/category/news
Ainsi,l'archive "Harrison Ford" dans votretaxonomie
actors
serait:http://myblogsite.com/actors/harrison-ford
The archive link for any taxonomy follows this pattern:
http://{siteurl}/{taxonomy}/{term}
For example, the category "news" on "myblogsite.com" would have the following archive URL:
http://myblogsite.com/category/news
So the "Harrison Ford" archive in your
actors
taxonomy would be:http://myblogsite.com/actors/harrison-ford
-
alorsest-ilpossible d'utiliser le `http://{siteurl}/{taxonomie}`pour l'archive detaxonomie?so is it possible to use the `http://{siteurl}/{taxonomy}` for the taxonomy archive ?
- 0
- 2012-04-10
- mrzmyr
-
Vous deveztoujours spécifier le *terme * dans lataxonomiepour laquellegénérer l'archive.You still need to specify the *term* within the taxonomy to generate the archive for.
- 0
- 2012-04-10
- EAMann
-
Cen'estpastoujours correct.Un utilisateurpeutmodifier lapartie `{taxonomie}` de cette structure dans lesparamètres depermalien.Parexemple,si vous avez la catégorie «non catégorisé»,l'urlpar défautest «http://{siteurl}/category/non catégorisé».Mais si vousmodifiez `category_base` dans lesparamètres dupermalienen`topics`,parexemple,ce serait `http://{siteurl}/topics/uncategorized`.Donc uneformuleplusprécisepour les catégories serait `http://{siteurl}/{get_option ('category_base')}/uncategorized`This is not always correct. A user can change the `{taxonomy}` portion of that structure in the permalink settings. For example, if you have the category, `uncategorized`, the default url is `http://{siteurl}/category/uncategorized`. But if you change the `category_base` in the permalink settings to `topics`, for example, it would be `http://{siteurl}/topics/uncategorized`. So a more accurate formula for categories would be `http://{siteurl}/{get_option('category_base')}/uncategorized`
- 0
- 2018-10-04
- Sam
-
- 2012-04-09
utilisez get_term_link () :)
< EDIT:
Celapeut être utile: lien d'archivepour lataxonomie: get_the_term_list () .Du codex:
Renvoie une chaîne HTML determes detaxonomie associée à un articleet taxonomie donnée.Lestermes sont liés à leur liste determes respective pages.
il doit donc être lié à unidentifiant depublication,maisfait letravail d'archivage destermes detaxonomie.
use get_term_link() :)
EDIT:
This may be of use: archive link for the taxonomy: get_the_term_list(). From the codex:
Returns an HTML string of taxonomy terms associated with a post and given taxonomy. Terms are linked to their respective term listing pages.
so it needs to be linked to a post ID, but does the job of archiving taxonomy terms.
-
cen'estpas ce queje cherchais.vérifier lepost de Tom:je cherchais un lien d'archivepour lataxonomieelle-même.thats not what i looked for. check Tom's post: i was looking for archive link for the taxonomy itself.
- 0
- 2012-04-10
- mrzmyr
-
- 2012-04-09
Lorsque vous créez votretaxonomiepersonnalisée,vouspouvez y ajouter l'attribut
rewrite
.Cet attributpourrait définir un slug de réécriturepour votretaxonomie que vouspouvez utiliserpour le lien:register_taxonomy('actors', 'movies', array( // ... 'rewrite' => array( 'slug' => 'actors' ), // ... ));
Donc,pour créer un lienpour créer le lien d'archive detaxonomie,vouspouvez utiliser lemodèle suivant:
http://mysite.com/actors/actor-name
When you create your custom taxonomy, you can add attribute
rewrite
to it. This attribute could set rewrite slug for your taxonomy which you can use for link:register_taxonomy('actors', 'movies', array( // ... 'rewrite' => array( 'slug' => 'actors' ), // ... ));
So to create a link to create the taxonomy archive link you can use following pattern:
http://mysite.com/actors/actor-name
J'ai créé destypes demessagespersonnalisés & amp;taxonomiespersonnaliséespour ces derniers.
Exemple:
actors
(taxonomie)pourmovies
(type depublication).Je souhaitemaintenant afficher dansmon widget destermeset un lien
more
pour l'archive destermesactors
.Comment obtenir le lien/l'url de l'archive detaxonomie?