我希望保持在WordPress的同一轮循环中,第一个帖子将有6列,其他帖子将在6列中


苞米地里的蒙面妖
2025-03-20 10:50:27 (22天前)
  1. 我想留在WordPress的同一轮循环,第一个帖子将有6列,其他帖子将在6列。例如http://prntscr.com/mvx453我的HTML代码https:// PasteBin。低......

2 条回复
  1. 0# google你他吗 | 2019-08-31 10-32




    1. <?php
      // checks if there are any posts that match the query
      if (have_posts()) :
      $i=1;
      ?>

      <?php
      // If there are posts matching the query then start the loop
      while ( have_posts() ) : the_post();
      // the code between the while loop will be repeated for each post
      ?>

    2.     <h2 id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h2>
    3.     <p class="date-author">Posted: <?php the_date(); ?> by <?php the_author(); ?></p>
    4.     <?php if($i==1){ ?>
    5.         </div>
    6.         <div class="col-md-6">
    7.     <?php } ?>
    8. <?php
    9.     $i++;
    10.     // Stop the loop when all posts are displayed
    11. endwhile; ?>
    12. </div>
    13. <?php
      // If no posts were found
      else : ?>

      Sorry no posts matched your criteria.


      <?php endif; ?>

    14. </code>

登录 后才能参与评论