Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

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.

share|improve this answer
    
thanks for the help! –  Joe Bobby Nov 13 '12 at 5:10
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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