【问题标题】:How can I skip the first post in WordPress loop?如何跳过 WordPress 循环中的第一篇文章?
【发布时间】:2021-05-20 07:04:00
【问题描述】:

我想跳过或不显示第一篇文章。 我怎样才能跳过第一个帖子?

              <?php query_posts('cat=' . $tabish['opt-box1'] . '&showposts' . $tabish['opt-box1-count']); ?> 
                <?php while (have_posts()) : the_post(); ?>
                    <div class="section-left-title">
                        <ul>
                            <li>
                                <a href="<?php the_permalink(); ?>"><i class="fa fa-angle-double-left"></i>
                                    <?php the_title(); ?>
                                </a>
                                <p class="card-text"><small class="text-muted"><?php the_time('d M Y'); ?> </small></p>
                            </li>
                        </ul>
                    </div>
                <?php endwhile; ?>
                <?php wp_reset_query(); ?>

【问题讨论】:

标签: php wordpress


【解决方案1】:
<?php query_posts( 'cat=' . $tabish['opt-box1'] . '&showposts' . $tabish['opt-box1-count'] ); 
    $i = 0; 
    while( have_posts() ) { the_post(); 
        if( $i > 0 ){ ?>
            <div class="section-left-title">
                <ul>
                    <li>
                        <a href="<?php the_permalink(); ?>"><i class="fa fa-angle-double-left"></i>
                            <?php the_title(); ?>
                        </a>
                        <p class="card-text"><small class="text-muted"><?php the_time('d M Y'); ?> </small></p>
                    </li>
                </ul>
            </div>
        <?php 
        } 
        $i++; 
    } 
wp_reset_query(); ?>

【讨论】:

  • 我有这个错误Parse error: syntax error, unexpected 'endwhile' (T_ENDWHILE)
  • 我使用了修改后的代码,不幸的是它没有显示任何帖子
  • 你有帖子吗?你把这段代码放在哪里?
  • 我输入了这段代码,不幸的是它没有显示任何帖子
  • 之前有显示吗?
最近更新 更多