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 would like to create an archive page with a list of my custom taxonomies that link to a page that shows posts with that taxonomy relationship.

I registered my taxonomy like this:

register_taxonomy('my_taxo', array('my_custom_post'), array(
            'hierarchical' => true,
            'label' => 'my taxo'
            'show_ui' => true,
            'query_var' => true,
            'show_in_nav_menus ' => true
            )
        );

What is the recommended way to create an archive page that can be visited at a url such as mysite.com/my_taxo or mysite.com/taxonomy/my_taxo.

Ideally the template file that will be used would be taxonomy-{taxonomy}.php.

Does this involve add_rewrite_rule? If so what might that look like?

share|improve this question
    
Could you clarify: Are you wanting a list of taxonomy terms, with a link for each that points to an archive of posts using of that term? –  Stephen Harris May 9 '12 at 16:03
    
yes, I need a list of the taxonomy terms. Each term will have a link to posts with that term. The part I am stuck on is the pretty URL and using an appropriate template file. –  Mike May 9 '12 at 16:04
add comment

1 Answer

up vote 0 down vote accepted

WordPress doesn't generate an 'archive of terms' automatically. However, you're current permalink structure is set up so that:

www.example.com/my_taxo/my-term

points to the 'my-term' archive page of the 'my_taxo' taxonomy (listing all posts with the 'my-term' tag).

So what you can do is create a page with slug 'my_taxo':

www.example.com/my_taxo

Assign this page a custom template which simply lists the taxonomy terms with links.

The simpliest way would be to use wp_list_categories()

<?php
$args = array(
  'taxonomy'     => 'my_taxo',
  'orderby'      => 'name',
  'hierarchical' => 1
  'title_li'     => ''
);
?>

<ul>
<?php wp_list_categories( $args ); ?>
</ul>

Alternatively you can use get_terms to return an array of terms in that taxonomy, which you can loop through and display the terms.

Neither will handle pagination automatically - but get_terms allows you to specify both a limit and an offset - so you could handle pagination yourself if this is necessary.

share|improve this answer
    
Great, I think I might have over thought this one. Creating a page in the admin will work just fine. We can leave the URL rewriting for another day... Thanks! –  Mike May 9 '12 at 18:09
    
You shouldn't need any custom rewriting or did you want the taxonomy/my_taxi structure? –  Stephen Harris May 9 '12 at 18:50
    
Well, if you wanted to avoid having to create the page in the admin for a url such as mysite.com/my-taxo I think it would require a url rewrite rule. –  Mike May 10 '12 at 18:49
add comment

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.