【问题标题】:Show Product category list in Woocommerce Wordpress Plugin without thumbnails在没有缩略图的 Woocommerce Wordpress 插件中显示产品类别列表
【发布时间】:2013-04-08 13:25:50
【问题描述】:

我正在使用以下短代码列出 woocommerce Wordpress 插件中的产品类别

<?php echo do_shortcode('[product_categories number=""]'); ?>

问题是我需要删除的类别缩略图。我想把它隐藏起来,用 CSS 做这件事似乎很麻烦。无论如何我可以列出类别而不显示缩略图吗?

【问题讨论】:

    标签: wordpress woocommerce


    【解决方案1】:

    您可以使用以下内容:

    $args = array( 'taxonomy' => 'product_cat' );
    $terms = get_terms('product_cat', $args);
    
    if (count($terms) > 0) {
        echo '<p class="my_term-archive">';
        foreach ($terms as $term) {
            echo '<a href="/term-base/' . $term->slug . '" title="' . sprintf(__('View all post filed under %s', 'my_localization_domain'), $term->name) . '">' . $term->name . '</a>';    
        }
        echo '</p>';
    }
    

    【讨论】:

    • 如何获取图片?我试过$term-&gt;image & $term-&gt;url
    • print_r($terms) 看看你在输出中得到了什么。如果术语有图像,它应该在数组中
    • 哦,我明天一整天都在寻找 print_r 函数!谢谢
    • 可以修改以显示孙类别吗?
    • @danyo 我需要最畅销的类别,我该如何获取它们?
    【解决方案2】:

    这是我用来按字母列出所有类别的列表,不包括空字母和类别特色图片!

    你需要做的就是按照你想要的方式来设计它;)

    <?php
    
    /* Define which category // to list child categories array('parent'=>42) 42 is category ID */
    $designers = get_terms('product_cat', array('parent'=>42));
    
    /* If categ not empty for each designer take first letter */
    if ( !empty( $designers ) && !is_wp_error( $designers ) ){    
        $term_list = [];    
        foreach ( $designers as $designer ){
            $letter = strtoupper($designer->name[0]);
            $designer_list[$letter][] = $designer;
        }
    unset($designer);
    
    
        foreach ( $designer_list as $key=>$value ) {
            /* Wrap around each designer */
            echo '<div><span>' . $key . '</span><ul>';
    
            foreach ( $value as $designer ) {
                // Set thumbnail
                $thumbnail_id = get_woocommerce_term_meta( $designer->term_id, 'thumbnail_id', true );
                // get the image URL
                $image = wp_get_attachment_url( $thumbnail_id );
                /* List designers */
                echo '<li><a href="' . get_term_link( $designer ) . '" title="' . sprintf(__('Products by %s', 'my_localization_domain'), $designer->name) . '">' . $designer->name . '<img src=" ' .$image.' "" alt="" /></a></li>';
            }
            /* end Wrap around designer */
            echo '</ul></div>';
        }?>
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-24
      • 2019-01-24
      • 2017-05-24
      • 2012-10-26
      • 2014-04-06
      • 2019-01-07
      相关资源
      最近更新 更多