Last active
August 29, 2015 14:04
-
-
Save dbernar1/3d0af36978226b59cd80 to your computer and use it in GitHub Desktop.
Content from another site
This file contains 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 | |
define( 'PRODUCT_QUERY_VAR', 'product__dbernar1' ); | |
define( 'PRODUCT_URL_PREFIX', 'products' ); | |
function get_permalink__dbernar1( $post = null ) { | |
if ( is_null( $post ) ) global $post; | |
return site_url( PRODUCT_URL_PREFIX . '/' . $post->post_name ); | |
} | |
add_action( 'init', 'create_post_type_rewrite_rules__dbernar1' ); | |
function create_post_type_rewrite_rules__dbernar1() { | |
add_rewrite_tag( '%' . PRODUCT_QUERY_VAR . '%', '([^&]+)' ); | |
add_rewrite_rule( '^' . PRODUCT_URL_PREFIX .' /([^/]*)/?', 'index.php?' . PRODUCT_QUERY_VAR . '=$matches[1]', 'top' ); | |
} | |
add_action( 'wp', 'show_product_in_current_site__dbernar1' ); | |
function show_product_in_current_site__dbernar1() { | |
$viewing_product = get_query_var( PRODUCT_QUERY_VAR ); | |
if ( $viewing_product ) { | |
allow_theme_to_overwrite_template__dbernar1( $named = 'single-product.php' ); | |
} | |
} | |
function allow_theme_to_overwrite_template__dbernar1( $template_filename ) { | |
if ( $overridden_template = locate_template( $template_filename ) ) { | |
load_template( $overridden_template ); | |
} else { | |
load_template( dirname( __FILE__ ) . '/templates/' . $template_filename ); | |
} | |
die; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is missing other pieces to actually be a whole solution, I created it to fill in the blanks of a guy who was already partway there.
Get in touch ( in a way listed at http://gravatar.com/dbernar1 ) if you need more info.