du59131 2015-11-12 10:06
浏览 115

Woocommerce - 产品类别页面404错误

I have been working on a plugin based on woocommerce. As a part of this I am trying to list all the category links in a page using a shortcode and I have succeeded in this.

The issue is all the category links with zero products are returning 404 error page where as the link works fine if the category has one or more products. Did anyone face this issue earlier?

Updating with Code:

 $args = array('taxonomy' => 'product_cat', 'hide_empty' => false, 'parent' => 0, 'exclude' => 723);
$terms = get_terms('product_cat', $args);
if (!$category instanceof WP_Error) {
    foreach ($terms as $term):
        ?>
        <ul class="col-md-3 col-lg-3 col-sm-6 col-xs-6 directory_catblock">
            <h3>

                <a href="<?php echo site_url() . '/' . $term->slug; ?>"><?php echo $term->name; ?></a>
            </h3>
            <?php
            $args_sub = array('taxonomy' => 'product_cat', 'hide_empty' => false, 'parent' => $term->term_id);
            $terms_sub = get_terms('product_cat', $args_sub);
            foreach ($terms_sub as $term_sub):
                ?>
                <li>
                    <a href="<?php echo site_url() . '/' . $term->slug . '/' . $term_sub->slug; ?>"><?php echo $term_sub->name; ?></a>
                </li>
        <?php endforeach; ?>
        </ul>
<?php endforeach;}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 微信会员卡接入微信支付商户号收款
    • ¥15 如何获取烟草零售终端数据
    • ¥15 数学建模招标中位数问题
    • ¥15 phython路径名过长报错 不知道什么问题
    • ¥15 深度学习中模型转换该怎么实现
    • ¥15 HLs设计手写数字识别程序编译通不过
    • ¥15 Stata外部命令安装问题求帮助!
    • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
    • ¥15 TYPCE母转母,插入认方向
    • ¥15 如何用python向钉钉机器人发送可以放大的图片?