Asique cree un archivo llamado "products-subcategory.php" en plugins/bezel-addons/vc/shortcodes/。Y lo incorporé en plugins/bezel-addons/vc/shortcodes.php en mi caso mi plantilla es la Bezzel https://themeforest.net/item/bezel-creative-multipurpose-wordpress-theme/20014332
Pero creo que puedes implementarlo en cualquiera que 使用 Visual Composer o WP Bakery。
因此,在 plugins/bezel-addons/vc/shortcodes/ 中创建一个名为“products-subcategory.php”的文件。
我将它合并到 plugins/bezel- addons /vc/shortcodes.php在任何使用 Visual Composer 或 WP Bakery 的人身上实现它。
产品-subcategory.php。
<?php
/* Product subcategory */
vc_map(
array(
'name' => 'Product subcategory',
'base' => 'bezel_products_subcategory',
'icon' => 'ti-align-left',
'description' => 'Product subcategories',
'category' => __( 'Bezel', 'bezel-addons'),
'params' => array(
array(
'type' => 'dropdown',
'param_name' => 'orderby',
'heading' => 'Order BY',
'value' => array(
'Name' => 'name',
'ID' => 'term_id'
),
),
array(
'type' => 'dropdown',
'param_name' => 'order',
'heading' => 'Order',
'value' => array(
'Upward' => 'ASC',
'Falling' => 'DESC'
),
),
array(
'type' => 'dropdown',
'param_name' => 'empty',
'heading' => 'Show empty subcategories',
'value' => array(
'Yes' => 0,
'No' => 1
),
)
)
)
);
add_shortcode( 'bezel_products_subcategory', 'bezel_products_subcategory' );
function bezel_products_subcategory( $atts ) {
global $wp_query;
extract( shortcode_atts( array(
'taxonomy' => 'product_cat',
'orderby' => 'name',
'order' => 'ASC',
'empty' => 0,
'hierarchical' => 1
), $atts ) );
$cat = get_queried_object();
$category_id = ($cat->parent) ? $cat->parent : $cat->term_id;
$args2 = array('taxonomy' => $taxonomy,'parent' => $category_id,'hierarchical' => $hierarchical, 'orderby' => $orderby, 'order' => $order,'hide_empty' => $empty);
$categories = get_categories( $args2 );
$categories_cnt = count(get_categories( $args2 ));
$selcat[$cat->term_id] = 'current-cat';
if ($categories_cnt != 0){
$sub_cats = get_categories( $args2 );
if($sub_cats) {
$output = '<div class="vc_wp_categories wpb_content_element">';
$output .= '<div class="widget widget_categories">';
$output .= '<ul>';
foreach($sub_cats as $sub_category) {
$output .= '<li class="cat-item cat-item-'.$sub_category->term_id.' '.$selcat[$sub_category->term_id].'"><a href="'.get_category_link($sub_category->term_id).'">'.$sub_category->cat_name.'</a></li>';
}
$output .= '</ul>';
$output .= '</div>';
$output .= '</div>';
}
}
return $output;
}
?>
Espero que le sirva a alguien。
我希望这可以帮助别人。