【问题标题】:How can I show 4 products in each row in woocommerce?如何在 woocommerce 的每一行中显示 4 个产品?
【发布时间】:2013-12-10 05:15:48
【问题描述】:

我正在为 woocomerce 使用自定义主题!目前我正在使用下面的代码来获取产品!它目前连续显示 5 个产品。

我想在每行显示 4 个产品?我该怎么做?

<?php if ( have_posts() ) : ?>
      <?php woocommerce_content(); ?>
      <?php endif; ?>

【问题讨论】:

    标签: php wordpress woocommerce


    【解决方案1】:

    您需要在调用循环之前设置每页的帖子数。试试这个:

    <?php if ( have_posts() ) : ?>
        <?php query_posts('posts_per_page=4'); ?>
        <?php woocommerce_content(); ?>
    <?php endif; ?>
    

    更新

    似乎这可以使用 CSS 来完成。因此,如果您需要每行列出 4 个产品,请在 stlye.css 中的第 2980 行进行此更改。

    .container .products li {width: 19%!important;}
    

    .container .products li {width: 23%!important;}
    

    更新1

    这仅通过 css 是不可能的。您需要将 div 包裹在 li 标签周围。更改您的代码,使其具有adds div after each 4 li 标记。所以你需要在一个 div 中包装 4 个 li 标签。这是我们可以使事情看起来像您想要的方式的方式。另一种选择是为每个 li 标签添加一个height or min-height

    希望对你有帮助

    【讨论】:

    • @DebakantMohanty 你能把 wp_debug 设为 true 并检查错误吗
    • 是的,我将 wp_debug 定义为 true,但我在这里看不到任何错误,还有一件事我不想每页显示 4 个产品我只想每页显示 20 个产品和每页 4 个产品排!希望这很清楚!
    • @DebakantMohanty 抱歉,我误解了您的要求。你有我可以检查的网址吗?上面的代码是否每页列出 5 个产品?如果您删除 query_posts 是否有效?
    • 好的,这是我的网站网址:wp.raddyx.in/Demo/?product_cat=nokia-mobiles 我已经删除了 query_posts,现在 irs 列出了我所有的产品,但我需要的是第 5 个产品应该从一个新行开始!
    • @DebakantMohanty 这仅显示一排有 5 个产品,对吗?那么如何列出这 20 款产品呢?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-17
    • 2012-09-02
    • 2018-12-03
    • 2015-08-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多