0

I'm really struggling to organise a site that will hold quite a lot of content. This example is reduced, but contains the crux of my problem.

The site features several clubs.

  • Games club
  • Juggling club
  • Dance club
  • etc...

Each club needs to publish news and events.

I have created a custom taxonomy called club and custom post types for news and events. My thinking being that when someone creates an event, they attribute it to their club using the taxonomy.

Ideally I wanted a url structure such as www.mysite.com/juggling-club/ (which would use a taxonomy template to display some content). Then www.mysite.com/juggling-club/events (which would list all the events that a club was holding).

It seems WordPress needs the taxonomy in the URL (www.mysite.com/club/juggling-club) which I could maybe live with, but I'm really struggling with how to display the different custom post types neatly based on taxonomy, and how I can organise my templates.

www.mysite.com/club/juggling-club/?post_type=events does filter my content, but checking the code it seems to just call the events post type archive template, and makes it hard to target the taxonomy as well.

Am I missing a much simpler option here?

Do I need to do a lot of re-write rules? If I do, how will I get WordPress to find my templates to customise the look of specific sections?

Thanks in advance for any insight!! Kind regards.

0

To me it would seem that your Games Club, Juggling club, etc... Are basically users. You say they need to be able to create their own posts, events, etc...

So you could do it that way as well. It depends if they are actual users from each club, or if someone is posting the content for everything. In the second case I would probably use taxonomies as you suggest.

  • Thanks, yes it might be the case that a user is entering content for various clubs, so I have settled on custom taxonomy. – Joseph186 Dec 14 '16 at 12:46
0

I have been working on this and have arrived at a solution I am happy with. I hope it makes sense at a WordPress level!

I have decided to keep the taxonomy term in the urls, I want to mess with the default WordPress behaviour as little as possible, and the URL still reads fine. (eg: www.mysite.com/club/juggling-club)

I have used a rewrite rule to resolve my post_type query var (eg: www.mysite.com/club/juggling-club/?post_type=events becomes www.mysite.com/club/juggling-club/events to list only events at the juggling club)

function mytest_rewrite_rule() {
    add_rewrite_rule(
        'club/([\-\w+]*)/([\w+]*)/?$', 
        'index.php?club=$matches[1]&post_type=$matches[2]',
        'top'
    );
}
add_action('init', 'mytest_rewrite_rule', 10, 0);

To follow on from that structure, I wanted my custom posts to have a url www.mysite.com/club/juggling-club/event/sponsored-juggle. With help from this post I created a custom term in my cpt's rewrite slug (club/%club%/event) that upholds my url pattern. WordPress needs some code to handle this:

function mytest_cpt_rewrite( $link, $post ) {
if ( $post->post_type === 'events' ) {
    if ( $terms = get_the_terms( $post->ID, 'club' ) )
            $link = str_replace( '%club%', current( $terms )->slug, $link );
        }
    return $link;
}
add_filter( 'post_type_link', 'mytest_cpt_rewrite', 10, 2 );

In summary, I have ended up with a logical structure:

www.mysite.com/club/juggling-club - Will be a general club landing page
www.mysite.com/club/juggling-club/events - Show all of a custom post type
www.mysite.com/club/juggling-club/event/sponsored-juggle - Show a specific post

I am considering making selection of club a required action when posting, as content will always need to belong to a club, and this should protect the URL pattern I have created.

I will see how things go with templates, I also plan on injecting the taxonomy term as a body css class to help with targetted styling of some elements.

Any further comments ideas still welcome! I hope this helps someone organising content.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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