3

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

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

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

4

2 回答 2

11

您可以使用以下内容:

$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>';
}
于 2013-06-25T19:45:01.457 回答
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>';
    }?>
}
于 2016-02-12T13:34:19.443 回答