Pagination Broken on Custom Loop – Showing Same Posts on Each Page
-
Hi all, and thanks preemptively for any advice you can provide on this.
The title says it all really – we’re trying to implement a custom loop for a certain category of posts (no custom post types, just straight up posts, only one category), our ‘Blog’ category. Here’s a link (the blue Older Posts button at the bottom is our pagination link, we’ve tried with the default links too):
https://www.eccrtest.com/2015-news/
Every new ‘page’ from the pagination just keeps showing the same 10 posts over and over. Here’s our code:
<?php if ( get_query_var('paged') ) { $paged = get_query_var('paged'); } elseif ( get_query_var('page') ) { $paged = get_query_var('page'); } else { $paged = 1; } $args = array('posts_per_page' => 10, 'cat'=> 17, 'offset' => 5,'paged' => $paged ); query_posts($args); ?> <!-- the loop --> <?php if ( have_posts() ) : while (have_posts()) : the_post(); ?> <!-- rest of the loop --> <div class="news_content"> <?php $catArray = array( "Health & Research", "Industry News", "International News", "Beginners Guide", "Ecig Technology", "Government & FDA", "Tips & Tricks", "Mini Review", "Ecig Promotions", "Other News" ); foreach(get_the_category() as $catcheck) { if (in_array($catcheck->cat_name, $catArray)){ $category_link = get_category_link( $catcheck->term_id ); echo "<h3 class='ecig cat-id-".$catcheck->term_id."'><a href='".esc_url( $category_link )."'>". $catcheck->cat_name ."</a></h3>"; echo '<h5>'.get_the_date(). '</h5>'; echo '<div class="person"><h4>'.__('By: ', 'ultimatum'). get_the_author().'</h4></div>'; echo '<div class="clear"></div>'; }else{ // do nothing } }?> <h2><a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2> <?php $url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );?> <?php the_post_thumbnail('full'); ?> <?php the_excerpt(); ?> <div class="news_share"> <ul class="rrssb-buttons"> <li class="arrow"><a href="<?php the_permalink(); ?>">READ THE FULL STORY</a></li> <li class="comments"><a href="<?php comments_link(); ?>"><?php comments_number( '0', '1', '%' ); ?> COMMENTS</a></li> <li><a class="fb_icon popupshare" href="https://www.facebook.com/sharer/sharer.php?u=<?php the_permalink(); ?>"></a></li> <li><a class="tw_icon popupshare" href="https://twitter.com/home?status=<?php the_title(); ?>%20<?php the_permalink(); ?>"></a></li> <li><a class="g_icon popupshare" href="https://plus.google.com/share?url=<?php the_title(); ?>%20<?php the_permalink(); ?>"></a></li> <li><a class="in_icon popupshare" href="https://www.linkedin.com/shareArticle?mini=true&url=<?php the_permalink(); ?>&title=<?php the_title(); ?>&summary=<?php the_excerpt(); ?>"></a></li> <li><a class="p_icon popupshare" href="https://pinterest.com/pin/create/button/?url=<?php the_permalink(); ?>&media=<?php echo $url;?>&description=<?php the_title(); ?>"></a></li> <li><a class="mail_icon popupshare" href="mailto:?subject=<?php the_title(); ?>&body=<?php the_permalink(); ?>"></a></li> <li class="share_icon"><a>SHARE</a></li> </ul> <div class="clear"></div> </div> </div> <!-- the title, the content etc.. --> <?php endwhile; ?> <!-- pagination --> <div class="posts"> <?php next_posts_link('VIEW OLDER POSTS'); ?> <?php previous_posts_link('VIEW NEWER POSTS'); ?> </div> <?php else : ?> <!-- No posts found --> <?php endif; ?>
We’ve spent roughly two whole days trying to figure this out cumulatively and we’re getting nowhere. We’ve been through all the posts we could find here, and on StackOverflow, and several other sources.
We’ve read through tutorials, tried a lot of different things, from changing the query_post to a new instantiation of the query, to using our theme’s custom loop widget, to no avail.
It’s important I guess to note that we’re piping the above code into the page via the ‘PHP Code for posts’ plugin (basically PHP code passed into the page via snippet shortcodes).
Can anyone help us figure out why our loop isn’t paginating correctly? Even a gentle shove in the right direction would be a good start if possible ??
Thanks!
- The topic ‘Pagination Broken on Custom Loop – Showing Same Posts on Each Page’ is closed to new replies.