使用 "while (have_posts()) : the_post();" 时 wordpress category.php 页面中的循环问题

loop problem in category.php page in wordpress when using "while (have_posts()) : the_post();"

我想使用 while (have_posts()) : the_post();> 循环 <div class="col-md-6"> 问题是这个循环在第一个 <div class="col-md-6"> 中创建了另一个 <div class="col-md-6"> 并且我失去了创建 2 列部分。下面是我的代码

获取此输出:

<div class="col-md-6">
    <div class="col-md-6">
        Post 1 details
    </div>
    <div class="col-md-6">
        Post 2 details
    </div>
</div>

我想要得到这个输出:

<div class="col-md-6">
    Post 1 details
</div>
<div class="col-md-6">
    Post 2 details
</div>



<section class="post-section">
        <div class="container">
            <div class="row">
                
                <?php if (have_posts()) : ?>
                <?php while (have_posts()) : the_post(); ?>
                <div class="col-md-6">
                    <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
                    <small><?php the_time('F jS, Y') ?> by <?php the_author_posts_link() ?></small>
                    <div class="entry">
                        <?php the_content(); ?>

                        
                    </div>

                    <?php endwhile; 

                    else: ?>
                    <p>Sorry, no posts matched your criteria.</p>


                    <?php endif; ?>
                </div>  
            </div>
        </div>
    </section>

您关闭了循环部分之外的 <div class="col-md-6">。 您的固定密码是:

<section class="post-section">
    <div class="container">
        <div class="row">
            <?php if (have_posts()) : ?>
                <?php while (have_posts()) :
                    the_post(); ?>
                    <div class="col-md-6">
                        <h2><a href="<?php the_permalink() ?>" rel="bookmark"
                               title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
                        <small><?php the_time('F jS, Y') ?> by <?php the_author_posts_link() ?></small>
                        <div class="entry">
                            <?php the_content(); ?>


                        </div>
                    </div>
                <?php endwhile;

            else: ?>
                <p>Sorry, no posts matched your criteria.</p>
            <?php endif; ?>
        </div>
    </div>
</section>