【问题标题】:Brand Menu WP All Import品牌菜单 WP All Import
【发布时间】:2022-01-12 12:28:25
【问题描述】:

我正在为我的一个主要销售移动设备的客户开发一个自定义主题。我使用 WP All Import Pro 每天 4 次通过 cron 作业导入产品,并且我每小时更新一次库存水平,同时使用来自外部 xml 链接的 cron 作业。 一切正常,但我的客户想要一个新菜单来按品牌名称显示所有产品。

有很多插件,如 WooCommerce 品牌、yith 和完美品牌,但它们都需要我手动添加品牌。 当有 550 多种产品并且每天至少更新 4 次时,这是不可能的。 如您在此屏幕截图中所见,我已在自定义字段中添加了品牌...

我添加了一个名为品牌的菜单,但只有自定义链接,无处可去。我不确定如何将品牌自定义字段编码到此菜单中。 Here 是我正在开发的网站,所以你知道需要什么..

非常感谢您的任何指点。

【问题讨论】:

    标签: wordpress woocommerce wordpress-theming wpallimport


    【解决方案1】:

    除了默认的 WordPress 侧边栏,您还可以使用自己的自定义侧边栏和新的自定义导航。

    请检查以下代码,您将看到类别列表:

    <nav>
        <ul>
            <?php
    
                $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 );
            foreach ($all_categories as $cat) {
                    if($cat->category_parent == 0) {
                            $category_id = $cat->term_id;       
                            echo '<li><a href="'. get_term_link($cat->slug, 'product_cat') .'">'. $cat->name .'</a></li>';
    
                            $args2 = array(
                                            'taxonomy'     => $taxonomy,
                                            'child_of'     => 0,
                                            'parent'       => $category_id,
                                            'orderby'      => $orderby,
                                            'show_count'   => $show_count,
                                            'pad_counts'   => $pad_counts,
                                            'hierarchical' => $hierarchical,
                                            'title_li'     => $title,
                                            'hide_empty'   => $empty
                            );
                            $sub_cats = get_categories( $args2 );
                            if($sub_cats) {
                                    foreach($sub_cats as $sub_category) {
                                            echo  $sub_category->name ;
                                    }   
                            }
                    }       
            }
            ?>
        </ul>
    </nav>
    

    只需为产品设置类别(作为品牌),您就会看到一个简单的结果。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-19
      • 1970-01-01
      • 2021-12-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多