• Hi, I have a problem with this code:
    <?php query_posts('category_name=news&posts_per_page=-1&offset=1'); ?>

    I am using “posts_per_page=-1” to query all the posts in the category. I would also like to offset by 1, but the result of this query is that all the posts are shown (= including the first one). What can I do?

    Thank you.
    NM

Viewing 2 replies - 1 through 2 (of 2 total)
  • Since you are not using pagination, it will not matter if you skip a post. Try something like this:

    query_posts('posts_per_page=-1&ignore_sticky_posts=1');
    if ( have_posts() ) {
       $number_of_posts = 0;
       while ( have_posts() ) {
          the_post();
          if( ++$number_of_posts == 1 ) continue;  // Skip the first post
          echo "$post->post_title<br />";
       }
    }
    Thread Starter mad_griffith

    (@niccolomineo)

    Thanks man, very interesting. I think I will switch to WP_Query, in the end, because I need to display all the posts from subcategories belonging to a certain subcategory. I will save this snippet though. Very useful.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘query_posts "posts_per_page" e "offset" conflicting?’ is closed to new replies.