• Hey there.

    I’m wondering if there is a way for me to get all the posts in one category – except the last one – using query_posts? The reason for this is that the last post has a different kind of format than the earlier ones (and the earlier ones will most likely change in numbers).

    As it is right now I have chosen to seperate the two by giving the last post in the category a different category-name and then using a second loop to show that post, like this:

    Page shows every post in category “Studier” (X amount of posts)
    Page shows every post in category “SistaStudier” (1 post)

    Want it to work this way:
    Page shows every post in category “Studier” except the last one (X-1)
    Page shows the last post in the category “Studier”.

    It’s not a hassle, but a friend of mine is going to use the page and the easier I can make it for her to update the page, the beter.

Viewing 1 replies (of 1 total)
  • various possiblities:

    a: use ‘offset’ in the second query; however, this will not work if you need pagination;

    b: it the latest post is shown first, you could use two loops; save the post id of the first post into a variable, and use it with the ‘post__not_in’ parameter in the second loop query;
    http://codex.wordpress.org/The_Loop#Multiple_Loops_in_Action
    possibly difficult with pagination;

    c: use one loop and a conditional statement with in the loop to catch the first post;
    example:

    if($wp_query->current_post == 0) :
    /*layout for first=latest post*/
    else :
    /*layout for all other posts*/
    endif;

    find all possible query parameter here: http://codex.wordpress.org/Class_Reference/WP_Query#Parameters

Viewing 1 replies (of 1 total)

The topic ‘Get all posts except the last one’ is closed to new replies.