Skip to content

Instantly share code, notes, and snippets.

@billerickson
Created September 10, 2012 20:36
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save billerickson/b8da6a8aa344d4cd89f0 to your computer and use it in GitHub Desktop.
Save billerickson/b8da6a8aa344d4cd89f0 to your computer and use it in GitHub Desktop.
Rewrite Endpoints
<?php
/**
* Rewrite Endpoint
*
*/
function be_endpoint() {
add_rewrite_endpoint( 'section', EP_PERMALINK );
}
add_action( 'init', 'be_endpoint' );
/**
* Custom Templates
*
*/
function be_custom_templates( $template ) {
if( ! is_singular( array( 'company', 'program', 'product' ) ) )
return $template;
$post_type = get_post_type();
$section = get_query_var( 'section' ) ? get_query_var( 'section' ) : 'overview';
$template = get_query_template( $post_type . '-' . $section );
return $template;
}
add_action( 'template_include', 'be_custom_templates' );
@billerickson
Copy link
Author

Going to /company/company-abc/ loads the Company ABC post using the 'company-overview.php' template.

Going to /company/company-abc/section/products.php loads the Company ABC post using the 'company-products.php' template.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment