这些天我一直在使用Woocommerce的代码(Woocommerce 3.8)。
对于许多用户来说,您可以将"class“作为一个值传递--例如,产品短代码:[products class="custom-class"],然后返回内容的包装器将具有custom-class。
But不适合!??
如果您有动态设计,并且希望能够根据页面上显示的内容更改相关产品的设计,则非常有用。
如果您查看伍尔商业博士的底部,您可以看到以下函数:
public static function related_products( $atts ) {
if ( isset( $atts['per_page'] ) ) {
$atts['limit'] = $atts['per_page'];
}
// @codingStandardsIgnoreStart
$atts = shortcode_atts( array(
'limit' => '4',
'columns' => '4',
'orderby' => 'rand',
), $atts, 'related_products' );
// @codingStandardsIgnoreEnd
ob_start();
// Rename arg.
$atts['posts_per_page'] = absint( $atts['limit'] );
woocommerce_related_products( $atts );
return ob_get_clean();
}正如您所看到的,shortcode_atts中没有类?
How来改变这个?
发布于 2020-04-23 20:09:51
I找到了一个解决方案,但我不确定它有多好
中
如果您从上面的链接到Woocommerce文档复制函数并使用它创建自己的短代码(it_related_products_function),然后将'class' => ''添加到参数中,那么您现在可以将'class‘传递给您的短代码。
function it_related_products_function( $atts ) {
if ( isset( $atts['per_page'] ) ) {
$atts['limit'] = $atts['per_page'];
}
$atts = shortcode_atts( array(
'limit' => '4',
'columns' => '4',
'orderby' => 'rand',
'class' => '',
), $atts, 'related_products' );
ob_start();
$atts['posts_per_page'] = absint( $atts['limit'] );
woocommerce_related_products( $atts );
return ob_get_clean();
}(
related.php中的属性并回显(如果设置为)
">3)现在您可以用“class”anywhere使用自定义的短代码https://wordpress.stackexchange.com/questions/364891
复制相似问题