Created
May 3, 2012 13:40
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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