0

Sorry for me, if I use incorrect words or sentenses, my English is poor, i.e. I'm from Russia. I have problem with pagination by using WP_query and pagination links like next_posts_link and previous_posts_link. My permalinks set is /%category%/%postname%/. WP 3.3.1. There is my code:

<?php
$paged = (get_query_var('page')) ? get_query_var('page') : 0;
$looks = new WP_Query('cat=3&posts_per_page=4&paged='.$paged);
while ($looks->have_posts()) : $looks->the_post(); ?>

    <ul class="look">
    <a class="look_thumb" href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>">
    <?php the_post_thumbnail('medium'); ?>
    </a>
    <h2><a href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    </ul>
<?php endwhile; ?>
<?php next_posts_link('<small class="page_navi">Другие записи >></small>'); ?>
<?php previous_posts_link('<small class="page_navi">Предыдущие записи <<</small>'); ?>
<?php wp_reset_postdata(); ?>

next_posts_link and previous_posts_link don't apear on page. This custom loop from my template page: 'looks_page.php'. What's wrong!? I'm trying fix it problem by during 3 days, but no results :(.

1

Looks like you're using the wrong query_var. It should be 'paged'

$paged = (get_query_var('paged')) ? get_query_var('paged') : 0;
  • Also, make sure you have at least 5 posts in your category. – joeljoeljoel Apr 10 '12 at 18:04
  • page is correct. see Pagination Note on WP_Query codex page. – Milo Apr 10 '12 at 18:11
  • WP Codex:Pagination Note: You should set get_query_var( 'page' ); if you want your query to work with pagination. Since Wordpress 3.0.2, you do get_query_var( 'page' ) instead of get_query_var( 'paged' ). The pagination parameter 'paged' for WP_Query() remains the same. – Timur Apr 10 '12 at 18:37

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.