0

I have a loop that I would like to Offset by 1 so the most recent post is not displayed, and another loop where I only want 1 item which would be the most recent post.

These are the loops I tried: for both:

Offset Loop: <?php query_posts('offset=1'); if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

and Most Recent Post Loop: <?php query_posts('posts_per_page=1'); if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

The page doesnt load for me when I tried this, any ideas?

1

Neither of those are complete loops. That is, in both you have the start of an if but not the end of it, and the start of a while loop, but no the end of it. Also, you shouldn't be using query_posts either, as it over writes the main query and is rarely the right function for pulling posts. get_posts would be better.

I would do this, using one as an example:

<?php $r = get_posts('offset=1'); 
    if ( !empty($r) ) : 
        foreach  ( $r as $post ) : 
            setup_postdata($post);
            // stuff
        endforeach;
    endif; ?>

That should solve your problem with the page not loading.

What you are doing can be done with a single loop though, since get_posts without the offset will pull everything. You just need to take the first element as the recent post and loop through the rest.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.