I am trying to build up a custom archive page. However, I would like this archive page to skip the first 5 posts.

I've been able to accomplish this with the offset property. However, the pagination seems to break.

Here's my code before the while:

 $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
 $wp_query = new WP_Query();
 $wp_query->query('posts_per_page='.get_option('posts_per_page').'&paged=' . $paged);

And this is the code I'm using for the pagination:

<?php wp_reset_postdata(); ?>

<div class="nav-previous" style="margin-bottom:24px; font-size:1.3em;"><?php next_posts_link(__('<span class="meta-nav">&laquo;</span> Entradas anteriores', '')) ?></div>
<div class="nav-next" style="margin-bottom:24px; font-size:1.3em;"><?php previous_posts_link(__('Entradas recientes <span class="meta-nav">&raquo;</span>', '')) ?></div>

Any help is deeply appreciated.



Of course it breaks. Pagination depends on the main query saved in the $wp_query object and you have overwritten that. When the next page load the ordinary wp_query that you have not overwritten will run and it won't match the one you've altered.

Create a filter for pre_get_posts to alter the main query.

function pregp_wpse_97354($qry) {
  // control where this runs
  if (is_main_query() && $qry->is_archive()) {

Notice // control where this runs. The line immediately following determines where this filter runs. I'd don't enough about your setup to get that right so I made something up. I am sure that that needs to be more specific.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.