我没有找到任何关于如何做到这一点的文档。因此,我周围的工作开始了。
在函数中注册侧栏。php文件(您可以将名称更改为您想要的任何名称):
function meir_widgets_init() {
register_sidebar( array(
\'name\' => \'Filters Sidebar\',
\'id\' => \'filters-sidebar\',
\'description\' => \'Sidebar for top filters.\',
\'before_widget\' => \'<div id="%1$s" class="widget %2$s">\',
\'after_widget\' => \'<div class="clear"></div></div></div></div>\',
\'before_title\' => \'<h3 class="widget-title">\',
\'after_title\' => \'</h3><div class="filter_box"><div class="filter_wrapper">\',
) );
add_action( \'widgets_init\', \'meir_widgets_init\' );
功能结束时。php文件:
if (!is_admin()) {
function woocommerce_price_filter_init2() {
global $woocommerce;
//if ( is_active_widget( false, false, \'price_filter\', true ) && ! is_admin() ) {
$suffix = defined( \'SCRIPT_DEBUG\' ) && SCRIPT_DEBUG ? \'\' : \'.min\';
wp_register_script( \'wc-price-slider\', plugins_url(\'/woocommerce/assets/js/frontend/price-slider\' . $suffix . \'.js\', __FILE__));
wp_enqueue_script(\'wc-price-slider\',\'\',true);
// array( \'jquery-ui-slider\' ), \'1.6\', true );
wp_enqueue_script(\'jquery-ui-slider\', false, array(\'jquery\'), false, true);
add_filter( \'loop_shop_post_in\', \'woocommerce_price_filter\' );
//}
}
add_action( \'init\', \'woocommerce_price_filter_init2\' );
}
function my_plugin_body_class($classes) {
$classes[] = \'woocommerce\';
$classes[] = \'woocommerce-page\';
return $classes;
}
add_filter(\'body_class\', \'my_plugin_body_class\');
然后在模板内创建一个名为
cache-woocommerce-nav-filter
在模板页面中,您希望显示自定义过滤器(本例中,我们的侧栏命名为过滤器侧栏,但可以更改为任何其他内容:
if(!function_exists(\'dynamic_sidebar\')){
}
else{
$hrcachfold = plugin_dir_path( __FILE__ )."cache-woocommerce-nav-filter/";
$hrcachefile = $hrcachfold.date("YmdH")."-cache.php";
$shop_page_url = get_permalink( woocommerce_get_page_id( \'shop\' ) );
$actual_link = "http://".$_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"];
if ( is_shop() ) {
if ( ($actual_link == $shop_page_url) AND !file_exists($hrcachefile) ) {
foreach ( glob ( $hrcachfold."*-cache.php" ) as $v ) {
unlink ($v);
}
ob_start();
dynamic_sidebar(\'filters-sidebar\');
$content = ob_get_contents();
$f = fopen( $hrcachefile, "w" );
fwrite( $f, $content );
fclose($f);ob_end_clean();
}
dynamic_sidebar(\'filters-sidebar\');
}
else {
$shoppage = file_get_contents($shop_page_url);
if ( ($actual_link == $shop_page_url) AND !file_exists($hrcachefile) ) {
foreach ( glob ( $hrcachfold."*-cache.php" ) as $v ) {
unlink ($v);
}
ob_start();
dynamic_sidebar(\'filters-sidebar\');
$content = ob_get_contents();
$f = fopen ( $hrcachefile, "w" );
fwrite( $f, $content );
fclose ($f);
ob_end_clean();
}
include($hrcachefile);
}
}