带偏移量的WordPress get_query_var()?

时间:2016-06-25 14:22:28

标签: wordpress

我目前正在使用get_query_var()来显示index.php页面中的所有帖子,我想知道是否可以使用任何偏移参数跳过最新帖子(我已在主页上显示它...) ?

    <div class="wrapper section-inner">
        <div class="content full-width">

            <?php if (have_posts()) : ?>
                <div class="posts">

                    <?php
                    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
                    $total_post_count = wp_count_posts();
                    $published_post_count = $total_post_count->publish;
                    $total_pages = ceil( $published_post_count / $posts_per_page );

                    if ( "1" < $paged ) : ?>
                            <div class="page-title">
                                <h4><?php printf( __('Page %s of %s', 'hemingway'), $paged, $wp_query->max_num_pages ); ?></h4>
                            </div>
                            <div class="clear"></div>
                    <?php endif; ?>

                    <?php while (have_posts()) : the_post(); ?>
                        <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
                            <?php get_template_part( 'content', get_post_format() ); ?>
                        </div> <!-- /post -->
                    <?php endwhile; ?>

                </div> <!-- /posts -->
            <?php endif; ?>

            <?php if ( $wp_query->max_num_pages > 1 ) : ?>
                <div class="post-nav archive-nav">
                    <?php echo get_next_posts_link( __('&laquo; Older<span> posts</span>', 'hemingway')); ?>
                    <?php echo get_previous_posts_link( __('Newer<span> posts</span> &raquo;', 'hemingway')); ?>
                    <div class="clear"></div>
                </div> <!-- /post-nav archive-nav -->
            <?php endif; ?>

        </div> <!-- /content -->
    </div> <!-- /wrapper -->

感谢您的反馈和建议

1 个答案:

答案 0 :(得分:0)

一种方法是跳过第一个索引:

<?php 
    $i = 0;
    while (have_posts()) : the_post(); 
      if($i > 0):
   ?>
    <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
       <?php get_template_part( 'content', get_post_format() ); ?>
    </div> <!-- /post -->
<?php 
     endif;
     i++;
    endwhile; 
?>