Is there a way of storing posts and pages under the same hierarchy?

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

Leave a Comment

tech