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 have a site that I'm making for a quarterly print magazine. I'm making all of the articles from all issues into Wordpress posts.

Every Article/Post belongs to an Issue and every Issue belongs to a Volume (Standard magazine stuff).

Instead of using Categories to represent a hierarchical relationship between Volume --> Issue I thought it would be better to use a Custom Taxonomy.

So I made a Custom Taxonomy of "Volume".

This is how I registered it in functions.php

function add_custom_taxonomies() {
// Add new "Locations" taxonomy to Posts
register_taxonomy('volume', 'post', array(
    // Hierarchical taxonomy (like categories)
    'hierarchical' => true,
    // This array of options controls the labels displayed in the WordPress Admin UI
    'labels' => array(
        'name' => _x( 'Volumes', 'taxonomy general name' ),
        'singular_name' => _x( 'Volume', 'taxonomy singular name' ),
        'search_items' =>  __( 'Search Issues' ),
        'all_items' => __( 'All Issues' ),
        'parent_item' => __( 'Parent Volume' ),
        'parent_item_colon' => __( 'Parent Volume:' ),
        'edit_item' => __( 'Edit Volume' ),
        'update_item' => __( 'Update Volume' ),
        'add_new_item' => __( 'Add New Volume' ),
        'new_item_name' => __( 'New Volume Name' ),
        'menu_name' => __( 'Volume-Issue' ),
    ),
    // Control the slugs used for this taxonomy
    'rewrite' => array(
        'slug' => 'volume', // This controls the base slug that will display before each term
        'with_front' => true, // Don't display the category base before "/volume/"
        'hierarchical' => true // "
    ),
));

} add_action( 'init', 'add_custom_taxonomies', 0 );

The issue is now that the slug for Taxonomies need to be unique so instead of the urls being very pretty like:

example.com/volume/volume1/issue-2/

i get

example.com/volume/volume-11/issue-1-volume-11/

This seems to be because the slugs "issue-1", "issue-2", "issue-3" and "issue-4" were taken up in the first volume and slugs need to be unique?

It's not the worst problem in the world but I though that since the Taxonomy for Issue is under a Volume which is unique I wouldn't have this problem. However, I do....

Anyway, can anyone suggest a better way to do this? Custom post Types possibly? Though I thought this was the perfect answer, just can't seem to get the URL's and slugs to cooperate.

I'd like to just come out with very pretty and predictable URLS like:

example.com/volume-1/issue-1/ example.com/volume-1/issue-2/ example.com/volume-9/issue-3/

I'd really appreciate the communities insight on this.

Thanks

Mike

share|improve this question

2 Answers 2

up vote 1 down vote accepted

There are a lot of ways you can solve this issue. What I'd do if it were me is to make "issue" its own taxonomy.

If issue is its own taxonomy, then the terms can be unique (and things are much less cluttered). An article will then belong to a volume, and also an issue. The trick is to create a hierarchy in the rewrite rules to make issues a part of volumes, and articles a part of both.

Here, I'm going to make your URLS look like this:

  • /volume/1/
  • /volume/1/issue/2/
  • /volume/1/issue/2/article-title/

In your article post type declaration, you'll want to set:

'rewrite' => array( 'slug' => 'volume/%volume%/issue/%issue%' )

In your issue taxonomy declaration, you'll want to set:

'rewrite' => array( 'slug' => 'volume/%volume%/issue' )

Lastly, you'll want to add filters to post_type_link and term_link so the auto-generate links don't contain %volume% and %issue%. Rather than reinvent the wheel, see "How do I append multiple taxonomies to the URL?" (amongst many, many others) on how to do that.

As always when making rewrite changes, be sure to flush your rewrite rules. You can do so by going to Settings->Permalinks and clicking "Save Changes".

share|improve this answer
    
this is great information let me try this. –  mmundiff May 28 '13 at 13:40
    
So if I make issue its own taxonomy I will still only have at most 4 issues. I want to be able to view all articles in a volume and all articles in an Issue. Can i do that with your method? –  mmundiff May 30 '13 at 18:08
    
Yes, absolutely. You'd also be able to do subsets, like issues 1 & 2 –  Matthew Boynes May 30 '13 at 20:35
    
So every post would belong to a volume (Volume 1 through 50) and an issue (issue 1-4 repeating)? But separate Taxonomies? Not parent-child relationship? Then to show articles Volume 1-Issue1 I would query to find posts which have both Issue 1 and Volume 1 as a term? To get all articles in a Volume I would just query for the volume taxonomy? Do I need a custom post type? I entered everything as regular posts. I'm still a little lost. I do appreciate your help here. –  mmundiff May 30 '13 at 21:06
    
You say you're lost, but it sounds like you've got it all figured out! It's not necessary to use a custom post type, posts are fine. –  Matthew Boynes May 30 '13 at 21:19

Your custom taxonomy try was nice, but I thing you should use another approach. Why not use the hierarchy of posts themselves ? By default, Posts are not hierarchical, but Pages are. It means they can have parents and can be ordered. Look at the hierarchical parameter in register_post_type.

If you create a master Page for each volume, then one sub page in this volume for each Issue, and then one sub sub page for each article within this Issue, you will end up with the correct URLs without any pain. You can even use custom page templates to make the difference between Volumes, Issues and articles and have the example.com/volume-1/ URL displaying the list of this volume issues.

share|improve this answer
    
So you are saying change all of my posts to pages and organize things that way? –  mmundiff May 28 '13 at 21:24
    
yes, that would be really simpler. You could use built-in Wordpress Pages, or create a custom post type that has the hierarchical property. –  Fabien Quatravaux May 30 '13 at 7:10

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.