dongle3217 2018-11-20 14:24
浏览 43

WooCommerce:排除在WordPress中管理的循环类别

I'm building a WooCommerce shop that shows 6 categories, handpicked by the shopowner, on the homepage.

I want to be able to manage the 6 categories in WordPress, so we can change things up every once in a while.

In the current situation, we're excluding one categorie ID (51) with an if-statement.

Here's the code:

$taxonomy     = 'product_cat';
$orderby      = 'name';
$show_count   = 0;      // 1 for yes, 0 for no
$pad_counts   = 0;      // 1 for yes, 0 for no
$hierarchical = 1;      // 1 for yes, 0 for no
$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 );
echo '<ul class="small-block-grid-1 medium-block-grid-3">';

foreach ($all_categories as $cat) {
    if ($cat->category_parent == 0 && $cat->term_id != 51) {
        $category_id = $cat->term_id;
        $thumbnail_id = get_woocommerce_term_meta( $cat->term_id, 'thumbnail_id', true );

        echo '<li class="single-news-post"><a href="'. get_term_link($cat->slug, 'product_cat').'">';

        $image = wp_get_attachment_url( $thumbnail_id );
        if ($image) {
            echo '<img src="' . $image . '" alt="' . $cat->name . '" />';
        }

        echo '<h3>'. $cat->name .'</h3>';
        echo '</a></li>';
    }
}

Is it possible to handpick the categories we want to show and manage these categories through our dashboard?

Thanks!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 Macbookpro 连接热点正常上网,连接不了Wi-Fi。
    • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
    • ¥15 linux驱动,linux应用,多线程
    • ¥20 我要一个分身加定位两个功能的安卓app
    • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
    • ¥15 IAR程序莫名变量多重定义
    • ¥15 (标签-UDP|关键词-client)
    • ¥15 关于库卡officelite无法与虚拟机通讯的问题
    • ¥15 目标检测项目无法读取视频
    • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析