WooCommerce产品类别(图片,标题,链接+说明)

时间:2015-08-26 15:54:17

标签: wordpress woocommerce

(woocommerce版本2.4.6 - wordpress版本4.2.2)

我希望在我的主页上显示3个产品类别(图片,标题,链接+描述:每只猫)

我试试这个

        <?php
// Déterminer des informations des catégories des produits
$args = array(
    'number'     => $number,
    'orderby'    => 'slug',
    'order'      => 'ASC',
    'hide_empty' => $hide_empty,
    'include'    => $ids
);
$product_categories = get_terms( 'product_cat', $args );
// Déterminer le nombre de catégories
$count = count($product_categories);
if ( $count > 0 ){ // S'il y a au moins une catégorie
    foreach ( $product_categories as $product_category ) {
        // Déterminer l'identifiant de la vignette d'une catégorie
        $thumbnail_id = get_woocommerce_term_meta( $product_category->term_id, 'thumbnail_id', true );
        // Extraire l'URL de la vignette
        $thumbnail_url = wp_get_attachment_thumb_url( $thumbnail_id );
        // Aficher la vignette et le nom de la catégorie comme un lien vers la page de la catégorie
        echo '<h2><img src="'.$thumbnail_url.'" /><a href="' . get_term_link( $product_category ) . '"> ' . $product_category->name . '</a></h2>';
    }
}

&GT;

..但它缺乏描述,我只会特别针对第3类展示(例如id 90,91,92)

也许有短码?

感谢

1 个答案:

答案 0 :(得分:2)

// Déterminer des informations des catégories des produits
$args = array(
   'number'     => $number,
   'orderby'    => 'slug',
   'order'      => 'ASC',
   'hide_empty' => $hide_empty,
   'include'    => $ids,
   'product_cat' => array(90,91,92), //add this in args
);

添加此行

echo $product_category->description;

之后

echo '<h2><img src="'.$thumbnail_url.'" /><a href="' . get_term_link( $product_category ) . '"> ' . $product_category->name . '</a></h2>';
相关问题