你必须自己写。了解WP电子商务的运作方式:
首先,“注册”主题文件的功能。
function wpsc_register_theme_file( $file_name ) {
global $wpec_theme_files;
if ( !in_array( $file_name, (array)$wpec_theme_files ) )
$wpec_theme_files[] = $file_name;
}
然后是查找主题文件的函数:
/**
* Checks the active theme folder for the particular file, if it exists then return the active theme directory otherwise
* return the global wpsc_theme_path
* @access public
*
* @since 3.8
* @param $file string filename
* @return PATH to the file
*/
function wpsc_get_template_file_path( $file = \'\' ){
// If we\'re not looking for a file, do not proceed
if ( empty( $file ) )
return;
// No cache, so find one and set it
if ( false === ( $file_path = get_transient( WPEC_TRANSIENT_THEME_PATH_PREFIX . $file ) ) ) {
// Look for file in stylesheet
if ( file_exists( get_stylesheet_directory() . \'/\' . $file ) ) {
$file_path = get_stylesheet_directory() . \'/\' . $file;
// Look for file in template
} elseif ( file_exists( get_template_directory() . \'/\' . $file ) ) {
$file_path = get_template_directory() . \'/\' . $file;
// Backwards compatibility
} else {
// Look in old theme path
$selected_theme_check = WPSC_OLD_THEMES_PATH . get_option( \'wpsc_selected_theme\' ) . \'/\' . str_ireplace( \'wpsc-\', \'\', $file );
// Check the selected theme
if ( file_exists( $selected_theme_check ) ) {
$file_path = $selected_theme_check;
// Use the bundled file
} else {
$file_path = WPSC_CORE_THEME_PATH . \'/\' . $file;
}
}
// Save the transient and update it every 12 hours
if ( !empty( $file_path ) )
set_transient( WPEC_TRANSIENT_THEME_PATH_PREFIX . $file, $file_path, 60 * 60 * 12 );
}elseif(!file_exists($file_path)){
delete_transient(WPEC_TRANSIENT_THEME_PATH_PREFIX . $file);
wpsc_get_template_file_path($file);
}
// Return filtered result
return apply_filters( WPEC_TRANSIENT_THEME_PATH_PREFIX . $file, $file_path );
}
在init钩子中,插件使用wpsc\\u register\\u theme\\u file()注册它需要的所有主题文件:
wpsc_register_theme_file( \'wpsc-single_product.php\' );
wpsc_register_theme_file( \'wpsc-grid_view.php\' );
wpsc_register_theme_file( \'wpsc-list_view.php\' );
wpsc_register_theme_file( \'wpsc-products_page.php\' );
wpsc_register_theme_file( \'wpsc-shopping_cart_page.php\' );
wpsc_register_theme_file( \'wpsc-transaction_results.php\' );
wpsc_register_theme_file( \'wpsc-user-log.php\' );
wpsc_register_theme_file( \'wpsc-cart_widget.php\' );
wpsc_register_theme_file( \'wpsc-featured_product.php\' );
wpsc_register_theme_file( \'wpsc-category-list.php\' );
wpsc_register_theme_file( \'wpsc-category_widget.php\' );
然后,当实际需要该文件时,他们调用wpsc\\u get\\u template\\u file\\u path():
switch ( $display_type ) {
case "grid":
include( wpsc_get_template_file_path( \'wpsc-grid_view.php\' ) );
break; // only break if we have the function;
case "list":
include( wpsc_get_template_file_path( \'wpsc-list_view.php\' ) );
break; // only break if we have the file;
default:
include( wpsc_get_template_file_path( \'wpsc-products_page.php\' ) );
break;
}
显然,插件的代码看起来会有所不同,但原则应该是相同的。