为了账号安全,请及时绑定邮箱和手机立即绑定

WordPress 网格 PHP

WordPress 网格 PHP

PHP
子衿沉夜 2022-11-04 17:04:10
我在向我的项目中添加网格布局时遇到问题,代码如下:<?php while ( have_posts() ) : the_post(); ?>    <?php        $args = array(            'post_type'      => 'projects',            'posts_per_page' => 2,        );        $q    = new WP_Query( $args );    ?>    <div class="row">        <?php while ( $q->have_posts() ) : $q->the_post(); ?>            <div class="col-6">                <h3>                    <a href="<?php the_permalink(); ?>">                        <?php the_title(); ?>                    </a>                </h3>                <?php the_excerpt(); ?>            </div>        <?php endwhile; ?>        <?php wp_reset_postdata(); ?>    </div><?php endwhile; ?>它看起来像这样:图像。它只是重复 2 列网格的次数与我的帖子一样多。谁能帮我解决这个问题,为我的项目获得一个正常的网格布局?谢谢!
查看完整描述

1 回答

?
潇潇雨雨

TA贡献1833条经验 获得超4个赞

<?php while ( have_posts() ) : the_post(); ?>从顶部和<?php endwhile; ?>底部移除。因为您在该循环中有一个自定义 WP 查询。所以那里不需要默认的 Wordpress 后查询循环。



查看完整回答
反对 回复 2022-11-04
  • 1 回答
  • 0 关注
  • 93 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信