Post query and pagination problem
-
Not the sharpest marble in the toolbox when it comes to forums, so, I think first time ’round I posted this question in the wrong place, so, here it is again … hopefully in the right place this time-
The problem:
?I need to display one specific post ( let’s call it an introductory post to the archive ), in full, on page 1 of a custom category archive (exhibitions) – and it needs to be called in by ID. I can’t use the sticky feature to have it always show there because I’m using sticky to call in featured posts on the homepage and don’t want to interfere with my coding on that, and having it in a separate category etc., would interfere with the CMS functionality of the site. I could just continually change the date on it to always make sure it was the most recent in the category, but, that would be horribly hackish.
?I need navigation on page one to the remainder of the category posts – the actual individual exhibitions.
?Page two and on, need to exclude the introductory post that is on page one and show 4 posts ( exhibitions ) per page.Here is what I thought was my almost working solution ( minus a way to call in the first post by ID and still have it page to page 2 – hadn’t gotten that far ):
<?php $per_page = get_option('posts_per_page'); $paged = (get_query_var('paged') && get_query_var('paged') > 1) ? get_query_var('paged') : 1; $cat = (get_query_var('cat')) ? get_query_var('cat') : 0; $offset = ($paged > 1) ? ($per_page * ($paged - 1) + 1) - $per_page : 0; $show = ($offset == 0) ? 'posts_per_page=1' : 'posts_per_page='.$per_page; query_posts("paged=$paged&cat=$cat&offset=$offset&$show"); ?> <?php if ( $paged < 2 ) { ?> <div id="nav"><?php posts_nav_link(' ', '<img src="' . get_bloginfo('template_url') . '/images/navigation/larrow.png" />', '<img src="' . get_bloginfo('template_url') . '/images/navigation/rarrow.png" />'); ?></div> <?php if (have_posts()) : while (have_posts()) : the_post(); ?> //stuff// <?php endwhile; endif; ?> <?php } else { ?> <div id="nav"><?php posts_nav_link(' ', '<img src="' . get_bloginfo('template_url') . '/images/navigation/larrow.png" />', '<img src="' . get_bloginfo('template_url') . '/images/navigation/rarrow.png" />'); ?></div> <?php if (have_posts()) : while (have_posts()) : the_post(); ?> /stuff/ <?php endwhile; endif; ?> <?php } ?>
Unfortunately, what I discovered is that this solution has a flaw, and one post, the last of six total, is being excluded from being shown. There should be one post ( introductory ) on page one, followed by four ( exhibition posts ) on page two, followed by the last ( for now until more are posted ) exhibition post on page 3.
Instead, what I am getting is the introductory post on page one ( great ), four exhibition posts on page two ( great ) and no 6th post or option to navigate to page three. The last post is totally missing. And it is the last post that is missing, not the first, so, I’m baffled. Any wisdom anyone could give would be greatly appreciated of course.
I’m all ears and thank you in advance to anyone who can help me solve this~
- The topic ‘Post query and pagination problem’ is closed to new replies.