Skip to content

Instantly share code, notes, and snippets.

@zanematthew
Created May 3, 2012 13:40
Show Gist options
  • Save zanematthew/2585723 to your computer and use it in GitHub Desktop.
Save zanematthew/2585723 to your computer and use it in GitHub Desktop.
This is the entire routes file, this is inspired by Rails routes.rb file.
<?php
/**
* Any Custom Post Type "should" automatically be routed based on the following:
*/
add_action('template_redirect', function( $params=array() ) {
$post_type = null;
$taxonomy = get_query_var('taxonomy');
if ( get_query_var('post_type') ) {
$post_type = get_query_var('post_type');
} else {
global $post;
if ( $post ) {
$post_type = $post->post_type;
}
}
/**
* @todo rename bmx-race-event to event, hack for now.
* why do we need to check for 'any'
*/
if ( $post_type == 'bmx-race-event' || $post_type == 'any' )
$post_type = 'events';
$template = array(
'post_type' => $post_type,
'single' => VIEWS_DIR . $post_type . DS . 'index.html.php',
'archive' => VIEWS_DIR . $post_type . DS . 'all.html.php',
'search' => VIEWS_DIR . $post_type . DS . 'search.html.php', // search is speicific to cpt, make array
'taxonomy' => VIEWS_DIR . $taxonomy . DS . 'index.html.php',
'default' => VIEWS_DIR . 'home' . DS . 'index.php'
);
do_action( 'zm_template_redirect', $template );
}, 6);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment