1

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?

1 Answer 1

3

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

7
  • is it possible to differentiate between the post type in the query as well, like /farbe/black/post ?
    – hakre
    Oct 14, 2010 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?
    – fuxia
    Oct 14, 2010 at 18:38
  • no, not for this example.
    – hakre
    Oct 14, 2010 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.
    – fuxia
    Oct 14, 2010 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, 2010 at 8:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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