使用内置的WooCommerce小部件"Recents products“显示一个标题(文本),后跟一个无序的产品列表。令人惊讶的是,这两个主要元素(标题和列表)没有包装在任何容器中,这使得它很难设计样式,很难集成到主题中,最终也很难使用。在小工具菜单中也没有相应的选项。
还有什么办法可以把它们包装起来,我可能没有想到?
发布于 2015-04-08 13:03:51
WooCommerce使用Filters来帮助我们用默认的小部件覆盖HTML输出。
例如,我相信您所指的WooCommerce Products使用了woocommerce_before_widget_product_list和woocommerce_after_widget_product_list过滤器。您可以简单地挂钩您的函数并修改默认输出。如下所示:
add_filter( 'woocommerce_before_widget_product_list', 'my_theme_before_widget_product_list', PHP_INT_MAX );
add_filter( 'woocommerce_after_widget_product_list', 'my_theme_after_widget_product_list', PHP_INT_MAX );
function my_theme_before_widget_product_list( $html ) {
return '<div class="my-theme-product-list">' . $html;
}
function my_theme_after_widget_product_list( $html ) {
return $html . '</div><!-- /.my-theme-product-list -->';
}如果您在侧边栏中使用小部件,则可以使用register_sidebar函数的before_widget、after_widget、before_title和after_title参数。
https://stackoverflow.com/questions/29397624
复制相似问题