这是我的存档页代码
我想避免在第四个循环中重复发布;我想数第三圈的帖子
有4个回路
1个第一循环计数:1个post
  <?php 
  $count = 1;
  if (have_posts()) : while (have_posts()) : the_post();            
  if($count == 1) : ?>
 <a href="<?php the_permalink() ?>" rel="bookmark" title="" ><?php the_title(); ?></a> 
 2秒循环--计数=1个post
<?php if (have_posts()) : ?>
<?php $count = 1; ?>
<?php while (have_posts()) : the_post(); ?>
<?php $count++; ?>
<?php if ($count == 2) : ?> 
<a href="<?php the_permalink(); ?>" title=""><?php the_title(); ?>  </a> 
 3第三个循环--计数=5个post
<?php else : ?> 
<a href="<?php the_permalink(); ?>" title=""><?php the_title(); ?></a> 
<?php endif; ?>
<?php endwhile; ?>
<?php else : ?>
<h1>Most Viewed News</h1>
<?php endif; ?>
 4循环--计数=所有post的其余部分
<?php else : ?> 
<a href="<?php the_permalink(); ?>" title=""><?php the_title(); ?></a> 
 --ad计数--
<?php if ( $count == 3 || $count == 5 ) : ?>
<?php dt_show_ads();?> 
<?php endif; ?>
<?php endif; ?> 
<?php $count++; ?> 
<?php endwhile; ?> 
<?php else : ?>
<div class="post">
<h2 class="archiveTitle"><?php _e(\'Sorry\',\'linepress\');?></h2>
</div>
<?php endif; ?>
 
                SO网友:soulseekah
                我会不惜一切代价避免这种过度的缩进,尽管我还没有测试过,但这应该是可行的。请让我知道是否有语法错误,以便我可以更正它们。
<!-- first loop : 1 post -->        
<?php
    if ( have_posts() ):
        the_post(); ?>
        <a href="<?php the_permalink() ?>" rel="bookmark" title="" ><?php the_title(); ?></a> 
    <!-- second loop : 2 posts -->
    <?php
        if ( have_posts() ):
            $count = 0;
            while ( have_posts() ):
                the_post(); ?>
                <a href="<?php the_permalink(); ?>" title=""><?php the_title(); ?></a> 
                <!-- third loop : 5 posts -->
            <?php
                if ( ++$count == 2 and have_posts() ):
                    $count = 0;
                    while ( have_posts() ):
                        the_post(); ?>
                        <a href="<?php the_permalink(); ?>" title=""><?php the_title(); ?></a> 
                        <!-- fourth loop : the rest -->
                    <?php
                        if ( ++$count == 5 and have_posts() ):
                            while ( have_posts() ):
                                the_post(); ?>
                                <a href="<?php the_permalink(); ?>" title=""><?php the_title(); ?></a>
                        <?php
                            endwhile;
                        else: // fourth loop has no posts
                        endif;
                    endwhile;
                else: // third loop has no posts
                endif;
            endwhile;
        else: // second loop has no posts
        endif;
    else: // first loop has no posts
    endif;
?>
 一个更优雅的解决方案应该是这样的:
<?php
    $page_counts = array(1, 2, 5, 9999);
    foreach ($page_counts as $iteration => $max_count) {
        $count = $max_count;
        while ( have_posts() and $count-- ) {
            the_post(); ?>
            <a href="<?php the_permalink() ?>" title="" ><?php the_title(); ?></a> 
    <?php
        } else break; // No more posts to grab!
    }
?>
 同样,未经测试,可能包含不匹配的大括号或其他内容。