php 我如何才能使子类别功能缩略图在WordPress中可点击

h79rfbju  于 4个月前  发布在  PHP
关注(0)|答案(1)|浏览(61)

我使用此功能来显示wooCommerce子类别和产品在单独的列表我的问题是,它只使子类别名称可点击的链接,我也希望缩略图图像可点击和链接到实际类别。我如何才能实现这一点?谢谢。

function tutsplus_product_subcategories( $args = array() ) {
    $parentid = get_queried_object_id();

$args = array(
    'parent' => $parentid
);

$terms = get_terms( 'product_cat', $args );

if ( $terms ) {
    echo '<ul class="product-cats">';

    foreach ( $terms as $term ) {
        echo '<li class="category">';                 
            woocommerce_subcategory_thumbnail( $term );
            echo '<h2>';
                echo '<a href="' .  esc_url( get_term_link( $term ) ) . '" class="' . $term->slug . '">';
                    echo $term->name;
                echo '</a>';
            echo '</h2>';
        echo '</li>';
    }

    echo '</ul>';
}

}

字符串

3b6akqbq

3b6akqbq1#

我遇到了同样的问题。要使类别图像可点击,只需将woocommerce_subcategory_thumbnail放在一个href中,如下所示:

function tutsplus_product_subcategories( $args = array() ) {
    $parentid = get_queried_object_id();

$args = array(
    'parent' => $parentid
);

$terms = get_terms( 'product_cat', $args );

if ( $terms ) {
    echo '<ul class="product-cats">';

    foreach ( $terms as $term ) {
        echo '<li class="category">';                 
            $catlink = '<a href="' . esc_url( get_term_link( $term ) ) . '" class="' . $term->slug . '">';
                echo $catlink;
                woocommerce_subcategory_thumbnail( $term );
                echo '</a>';
                            echo '<h2>';
                                echo $catlink;                 
                    echo $term->name;
                echo '</a>';
            echo '</h2>';
        echo '</li>';
    }

    echo '</ul>';
}

}

字符串
我创建了一个变量$catlink,这样URL就不必被拉取两次。

相关问题