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 am developing the blog-template of my theme, which works as following: The user can input the total post-count to display on each blog-page ($blogpost_count). The blog itself lists post-entries in two different fashions, like so:

  • first, the newest X (X being equal to $blogpost_count) posts are listed regularly with query_posts,
  • then, the following 2 posts are listed with get_posts and an offset equal to $blogpost_count.

Now, the different between both fashions/queries is merely CSS. Meaning, the first list of posts has a certain style, and the second another style. Furthermore, the second list is always offset by the specified $blogpost_count, essentially displaying the adjacent posts - if available.

Here's my issue: This methodology works flawlessly on the first blog page. However, when the user navigates back to view older posts (i.e. with next_posts_link(), ending up on an is_paged() blog page), the offset does not "adjust" to the new number of displayed posts. Because of 'offset' => $blogpost_count, that variable still applies on e.g. the second blog page, even if there is only 1 post listed.

My logic tells me what I need something like this (simplified):

if(!is_paged()) { 
    'offset' => $blogpost_count;
} else {
    'offset' => $number_of_currently_displayed_posts_PLUS_off_all_newer_posts;
}

I hope I explained myself thoroughly.
Thank you!

EDIT: You can view a static HTML example of the blog-template, to hopefully, visually understand my concept better.

share|improve this question

2 Answers 2

up vote 1 down vote accepted

try:

if(!is_paged()) {      
    $post_offset = $blogpost_count; 
} else {     
    $post_offset = (get_query_var('paged')-1)*2+$blogpost_count; 
} 

...
...
   'offset' => $post_offset;
share|improve this answer
    
thanks a lot! This works beautifully. However, there's one minor drawback, and that is, making the previous/next_posts_link(s) understand how and what we're offsetting. This is my current code: pastie.org/3005879 - please read the comments for further understanding. That code solves the: non-paged and paged more-posts being properly offset AND the paged regular posts being also properly offset. –  cr0z3r Dec 12 '11 at 16:29

Sorry - answered to myself to soon. My solution partially fixed the offset, but it caused other issues. That said, my issue remains and I truly appreciate any help I can get.

Thank you!

share|improve this answer

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.