如果您根据产品类别快捷码创建自己的快捷码
function duck_product_categories( $atts ) {
global $woocommerce_loop;
$atts = shortcode_atts( array(
\'number\' => null,
\'orderby\' => \'name\',
\'order\' => \'ASC\',
\'columns\' => \'4\',
\'hide_empty\' => 1,
\'parent\' => \'\',
\'ids\' => \'\'
), $atts );
if ( isset( $atts[\'ids\'] ) ) {
$ids = explode( \',\', $atts[\'ids\'] );
$ids = array_map( \'trim\', $ids );
} else {
$ids = array();
}
$hide_empty = ( $atts[\'hide_empty\'] == true || $atts[\'hide_empty\'] == 1 ) ? 1 : 0;
// get terms and workaround WP bug with parents/pad counts
$args = array(
\'orderby\' => $atts[\'orderby\'],
\'order\' => $atts[\'order\'],
\'hide_empty\' => $hide_empty,
\'include\' => $ids,
\'pad_counts\' => true,
\'child_of\' => $atts[\'parent\']
);
$product_categories = get_terms( \'product_cat\', $args );
if ( \'\' !== $atts[\'parent\'] ) {
$product_categories = wp_list_filter( $product_categories, array( \'parent\' => $atts[\'parent\'] ) );
}
if ( $hide_empty ) {
foreach ( $product_categories as $key => $category ) {
if ( $category->count == 0 ) {
unset( $product_categories[ $key ] );
}
}
}
if ( $atts[\'number\'] ) {
$product_categories = array_slice( $product_categories, 0, $atts[\'number\'] );
}
$columns = absint( $atts[\'columns\'] );
$woocommerce_loop[\'columns\'] = $columns;
ob_start();
if ( $product_categories ) {
?>
<div class="woocommerce columns-<?php echo $columns;?>">
<ul class="products alternating-list">
<?php
foreach ( $product_categories as $category ) {
?>
<li class="product-category product first">
<a href="<?php echo get_category_link($category); ?>">
<?php
$thumbnail_id = get_woocommerce_term_meta( $category->term_id, \'thumbnail_id\', true );
$image = wp_get_attachment_url( $thumbnail_id );
if ( $image ) {
echo \'<img src="\' . $image . \'" alt="" />\';
}
?>
</a>
</li>
<li class="product-category product last">
<?php echo $category->name;
echo \'<div class="shop_cat_desc">\'.$category->description.\'</div>\';
?>
</li>
<?php
}
woocommerce_product_loop_end();
}
woocommerce_reset_loop();
return \'<div class="woocommerce columns-\' . $columns . \'">\' . ob_get_clean() . \'</div>\';
}
add_shortcode(\'dd_product_categories\', \'duck_product_categories\');
然后添加此CSS:
.alternating-list li:nth-child(4n+3) {
float: right !important;
}
当您调用快捷码时
【dd\\U product\\u categories number=“12”parent=“0”columns=“2”】
把columns=“2”放在那里,或者你可以把它硬编码到那里,如果你要这样做的话。
这包括图像侧面标题下的类别描述。像这样https://snag.gy/YVIBCl.jpg