0

I have 2 custom query in my home page. The 1st query shows just the last post somewhere in my theme. and the second query should display all the other posts as regular (excluding one last post showed up somewhere else in my theme). the problem shows when I use offset & I couldn't solve it in any way. here's first query:

<div class="col-sm-7 col-sm-pull-5 last-post-grid">
    <h2>Last Post</h2>
        <?php 
        $args = array(
            'post_type'     => 'post',
            'cat'           => '-4, -5, -6',
            'posts_per_page'=> 1,
            'post_status'   => 'publish',
        );
        $one_last_post = new WP_Query($args);

        if( $one_last_post-> have_posts() ): $one_last_post-> the_post();
                ?>
        <div class="last-post full">
            <div class="date">
                <p class="day"><?php echo get_the_date('j'); ?></p>
                <p class="month"><?php echo get_the_date('F'); ?></p>
            </div><!-- .date -->
            <h3><?php the_title(); ?></h3>
            <p><?php the_excerpt(); ?></p>
        </div><!-- .last-post .full -->
        <?php endif; wp_reset_postdata(); ?>
</div><!-- .last-post-grid -->

and my second query which supposed to show all posts excluding one last post:

<div class="col-sm-7 more-posts">
    <?php 
    $args = array(
        'category__not_in'  => array( 4, 5, 6 ),
        'posts_per_page'=> 10,
        'offset'        => 1,
        'paged'         => get_query_var( 'paged' ),
        );
        $wp_query = new WP_Query($args);

        if( $wp_query -> have_posts() ):
            $i = 0;
            while( $wp_query -> have_posts() ):
                $wp_query -> the_post(); 
                $i++;
                if( $i <= 3 ):
                ?>
                <div class="last-post full">
                    <img src="" alt="" />
                    <div class="date">
                        <p class="day"><?php echo get_the_date('j'); ?></p>
                        <p class="month"><?php echo get_the_date('F'); ?></p>
                    </div><!-- .date -->
                    <h3><?php the_title(); ?></h3>
                    <p><?php the_excerpt(); ?></p>
                </div><!-- .last-post .full -->

                <?php else: ?>

                <div class="last-post condensed">
                    <img src="" alt="" />
                    <h3><?php the_title(); ?></h3>
                    <div class="date">
                        <p>date here</p>
                    </div><!-- .date -->
                    <p><?php the_excerpt(); ?></p>
                </div><!-- .last-post .condensed -->
                <?php       endif; 
                        endwhile; 
                    endif;
                ?>

                <div class="row home-pagination">
                    <div class="col-sm-12">
                        <?php   pre_numeric_posts_nav(); ?>
                    </div>
                </div>

                <?php wp_reset_postdata(); ?>
            </div><!-- .more-posts -->

Unfortunately I couldn't fixed it by reading other questions on stackexchange, and this really overwhelmed me. So could you please help me on this ?

Thanks in advance.

  • 'offset' does not work with pagination. – Michael Oct 11 '16 at 4:58
  • After lots of frustration I decided to change the whole plan, so I changed whole coding structure and did my work in some other way. – startToday Oct 11 '16 at 15:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.