希望在 Wordpress 站点的两列中显示 archive.php

Looking to make archive.php display in two columns for Wordpress site

这里是 Wordpress 新手。试图让我的存档页面在两列中显示帖子,如下所示:

Post 1 Post 2

Post 3 Post 4

这是我们正在研究的 figma 的示例:https://ibb.co/N3XwtwD

我的问题是,我可以在我的文件中添加什么代码来实现这一点?我目前在此处插入的 html 部分有一些 bootstrap 类,它显示为一列,所以我不知道这些 类 是否会干扰任何东西.下面是我的 archive.php 代码:

<?php 

get_header();
?>

<div class="container mt-5 mb-5">
        <p class="font-size"><?php the_archive_title(); ?></p>
        <hr>
    </div>

<div class="container">
<?php 
  while(have_posts()) {

    the_post(); ?>

    <div class="row">

        <div class="col-lg-6">
            <p class="font-size text-center"><a href="<?php the_permalink();?>"><?php the_title();?></a></p>
            <img class="img-fluid mb-3"<?php
                        the_post_thumbnail(); 
                                ?>
            <p class="category-font">Published on <?php the_time('n.j.y');?></p>
            <p>Posted by <?php the_author_posts_link() ?></p>
        </div>
      </div>
<?php }
echo paginate_links();
?>


  </div>

  <?php
  get_footer();
  ?>

第一次在这里发帖,如有遗漏,请见谅。真的很感谢这个地方!

谢谢!

您需要每两个帖子创建一行,并且您必须连续添加两次 <div class="col-lg-6">。检查下面的代码。

<?php get_header(); ?>

<div class="container mt-5 mb-5">
    <p class="font-size"><?php the_archive_title(); ?></p>
    <hr>
</div>

<div class="container">
    <?php 
    $count = 1;
    while( have_posts() ) { the_post(); 
        if ( $count % 2 == 1){ ?>
            <div class="row">
        <?php } ?>
            <div class="col-lg-6">
                <p class="font-size text-center"><a href="<?php the_permalink();?>"><?php the_title();?></a></p>
                <?php the_post_thumbnail(); ?>
                <p class="category-font">Published on <?php the_time('n.j.y');?></p>
                <p>Posted by <?php the_author_posts_link() ?></p>
            </div>
        <?php if ( $count % 2 == 0 ){ ?>
            </div>
        <?php } $count++; ?>
    <?php } 
    if ( $count % 2 != 1 ) echo "</div>";
    echo paginate_links(); ?>
</div>

请替换为以下对您有帮助的代码。

<?php
get_header();
?>

<div class="container mt-5 mb-5">
        <p class="font-size"><?php the_archive_title(); ?></p>
        <hr>
    </div>

<div class="container">

<?php 
$counterval = 0;
  while(have_posts()) {
    the_post(); 

    $counterval++;
    if($counterval % 2 != 0)
    { ?>
        <div class="row">
    <?php } ?>
    <div class="col-lg-6">
            <p class="font-size text-center"><a href="<?php the_permalink();?>"><?php the_title();?></a></p>
            <?php $featured_img_url = get_the_post_thumbnail_url(get_the_ID(),'full');
            if(!empty($featured_img_url)){ ?>
                <img class="img-fluid mb-3" src="<?php echo esc_url($featured_img_url); ?>" />
            <?php } ?>            
            <p class="category-font">Published on <?php the_time('n.j.y');?></p>
            <p>Posted by <?php the_author_posts_link() ?></p>
        </div>
    <?php 
    if($counterval % 2 == 0)
    { ?>
    </div>
    <?php } ?>
    
<?php } ?>

<?php echo paginate_links();
?>


  </div>

  <?php
  get_footer();
  ?>