wordpress - 在滑块内显示 Woocommerce 产品类别
问题描述
我试图在滑块内显示我的所有产品类别
<div id="category-wrapper">
<div id="owl1" class="owl-carousel">
<div class="item">
<?php echo do_shortcode('[product_category category="main-cat"]'); ?>
</div>
<div class="item">
<?php echo do_shortcode('[product_category category="cat2"]'); ?>
</div>
<div class="item">
<?php echo do_shortcode('[product_category category="cat3"]'); ?>
</div>
<div class="item">
<?php echo do_shortcode('[product_category category="cat4"]'); ?>
</div>
...
</div>
</div>
但它输出这些类别而不是类别的产品。
我需要这样做: 链接图片每个框代表根目录中的一个产品类别。
解决方案
我自己做了,但子类别中的图像不起作用:
<div id="kategorie-nahlad">
<?php
$taxonomy = 'product_cat';
$orderby = 'name';
$show_count = 0;
$pad_counts = 0;
$hierarchical = 1;
$title = '';
$empty = 0;
$args = array(
'taxonomy' => $taxonomy,
'orderby' => $orderby,
'show_count' => $show_count,
'pad_counts' => $pad_counts,
'hierarchical' => $hierarchical,
'title_li' => $title,
'hide_empty' => $empty
);
$all_categories = get_categories( $args ); ?>
<div id="owl1" class="owl-carousel">
<?
foreach ($all_categories as $cat) {
$thumbnail_id = get_term_meta( $cat->term_id, 'thumbnail_id', true );
$image = wp_get_attachment_url( $thumbnail_id );
$image_alt = get_post_meta( $image->id, '_wp_attachment_image_alt', true );
if ($cat->category_parent == 0) {
$category_id = $cat->term_id;
echo '<div class="item text-center">';
echo '<br><a href="'. get_term_link($cat->slug, 'product_cat') .'"><img src="' . $image . '" alt="' . $image_alt . '">'. $cat->name .'</a>';
echo '</div>';
$args2 = array(
'taxonomy' => $taxonomy,
'child_of' => 0,
'parent' => $category_id,
'orderby' => $orderby,
'show_count' => $show_count,
'pad_counts' => $pad_counts,
'hierarchical' => $hierarchical,
'title_li' => $title,
'hide_empty' => $empty
);
$sub_cats = get_categories( $args2 );
if($sub_cats) {
foreach($sub_cats as $sub_category) {
$thumbnail_id_sub = get_term_meta( $cat->term_id, 'thumbnail_id', true );
$image_sub = wp_get_attachment_url( $thumbnail_id_sub );
echo '<div class="item text-center">';
echo '<br><a href="'. get_term_link($sub_category->slug, 'product_cat') .'"><img src="' . $image . '" alt="' . $image_alt . '">'. $sub_category->name .'</a>';
// echo apply_filters( 'woocommerce_subcategory_count_html', ' <div class="cat-count">' . $sub_category->count . '</div>', $category );
echo '</div>';
}
}
}
}
?>
</div><!-- KONIEC OWL1 -->
</div>
推荐阅读
- c# - Microsoft graph 电子邮件附件状态码 405。方法不允许
- r - R中粘贴函数的内容是什么,它是如何工作的?
- oop - How to implement Exp in Bool or IFF from the paper Extensibility for the Masses
- json - 将 JSON 发送到带有证书的端点并使用私钥
- python - 在 tkinter 中禁用按钮的正确方法是什么?
- excel - 将重复数据从行转换为列 Excel
- java - LWJGL Mac M1 - java.library.path 中没有 lwjgl
- string - 优化等值线
- ios - 如何在 swiftUI 中的滚动视图上将后退和前进按钮添加到 Hstack
- kubernetes - Neo4j 部署后访问