Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I created custom post types & custom taxonomies for these.

Example: actors (taxonomy) for movies (post type).

Now I want to show up in my widget some terms and a more link for the actors terms archive.

So guys, How do i get the taxonomy archive link / url?

PS.: Need some code? Request it the Comments.

share|improve this question

4 Answers 4

up vote 3 down vote accepted

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

share|improve this answer
    
The 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 –  M. Myer Apr 10 '12 at 1:51
1  
There 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. –  Tom J Nowell Apr 10 '12 at 10:01

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
share|improve this answer
    
so is it possible to use the http://{siteurl}/{taxonomy} for the taxonomy archive ? –  M. Myer Apr 10 '12 at 1:47
    
You still need to specify the term within the taxonomy to generate the archive for. –  EAMann Apr 10 '12 at 4:05

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
share|improve this answer

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.

share|improve this answer
    
thats not what i looked for. check Tom's post: i was looking for archive link for the taxonomy itself. –  M. Myer Apr 10 '12 at 1:53

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.