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'm working on a site which needs to have pages and posts sorted into the same categories. The pages have their own individual hierarchy structure.

Is there a way to do this using a custom taxonomy?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

Yes, a custom taxonomy is the best way to achieve this.

For a cat breeder site I’ve set a taxonomy for colors (in german: Farbe):

register_taxonomy(
    'farbe',
    array( 'post', 'page' ),
    array(
        'hierarchical'  => false,
        'label'         => 'Farbe (Fell)',
        'query_var'     => 'farbe',
        'rewrite'       => array('slug' => 'farbe')
    )
);

Note the third parameter array( 'post', 'page' ).

Now you can find all posts and page covering the color black at /farbe/black/.

That’s all, WP will do the rest for you. :)

Update

WordPress will search for a matching template.

To link to this taxonomy, add the following code to the meta data box (tags, categories, date etc.) of your posts:

echo get_the_term_list( $post->ID, 'farbe', ' · Farbe: ', ', ', '' );

Output:

<a href="http://example.com/farbe/black/" rel="tag">black</a>

Screenshot for taxonomy “Farbe” in the post edit screen:

alt text

share|improve this answer
    
is it possible to differentiate between the post type in the query as well, like /farbe/black/post ? –  hakre Oct 14 '10 at 18:24
    
Not per default. You could try to hook into such a request and sort it out with a custom query … but would you want to do that? –  toscho Oct 14 '10 at 18:38
    
no, not for this example. –  hakre Oct 14 '10 at 21:32
    
Sorry, I lost a ›why‹. :) Why would you want to do that? The difference between posts and pages is an internal; the user should never care about such things imho. –  toscho Oct 14 '10 at 22:10
    
Because pages are being used for content which doesn't change regularly but the users want the page content to also appear on the area of the site which displays news i.e. normal blog posts. I'm just trying to figure out the best way to organise the content of a site I have inherited. –  codecowboy Oct 15 '10 at 8:03

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.