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 trying to create a pagination system through my posts. Here my code:

<?php
  $paged = (intval(get_query_var('paged'))) ? intval(get_query_var('paged')) : 1;
  $args = array(
    'post_type' => 'programma_mensile',
    'paged' => $paged,
    'posts_per_page' => 1,
    'monthnum' => (date('n')-1),
    'year' => date('Y')         
  );
  query_posts($args);

      if (have_posts()) : while (have_posts()) : the_post(); ?>

      <div class="programmi-navigation">
        <div class="programmi-prev pagination pull-left"><?php next_posts_link(''); ?></div>
        <h4 class="programmi-title color-span pull-left"><?php the_title(); ?></h4>
        <div class="programmi-next pagination pull-left"><?php previous_posts_link(''); ?></div>
        <div class="clearfix"></div>
      </div>
      <?php $eventIds = preg_split( "/[\s,]+/", get('lista_eventi') ); ?>
      <?php endwhile; ?>          
<?php endif; ?>

Everything works fine without these parameters:

'monthnum' => ( date('n') - 1),
'year' => date('Y')

With these two parameters the query works but i cant get the previous and the next post link.

But i need them because want to show the post of the current month..even if a post for december is already pubblished.

share|improve this question
    
There are several different red flags in your code. Why are you using query_posts? Why are you not using pre_get_posts? Why does this code do that the template hierarchy cannot? Please explain what you are trying to accomplish rather than ask about a fix for your (possibly incorrect) attempt to accomplish whatever it is. –  s_ha_dum Nov 9 '13 at 16:24

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.