Support » Fixing WordPress » Query_posts loop and pagination

  • Resolved Luigino


    Hello everyone!!!!

    I have here this index.php

    <?php get_header(); ?>
    <div id="centerpiece">
            <div id="boxmodel-top">
                    <?php if (!is_single()) : ?>
                    <div id="boxmodel">
                            <div id="content-sticky">
                                            $category = get_the_category(''); $cat_slug = $category[0]->category_nicename;
                                            if (have_posts()) : while (have_posts()) : the_post();
                                                    echo '<div class="category_description">'; if (in_category('24')) the_content(); echo '</div>';
                                            endwhile; endif; wp_reset_query();
                    <?php else : ?>
                    <?php endif; ?>
                    <div id="boxmodel_main">
                            <div id="content">
                                    if (!is_single()) :
                                                    'category__not_in' => array(24, 44),
                                    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
                                            <?php if (in_category("24") || in_category("44")) continue; ?>
                                            <div class="post" id="post-<?php the_ID(); ?>">
                                                    <div class="post-head">
                                                            <div class="post-blocktitle">
                                                                    <h2 class="post-title"><a href="<?php the_permalink(); ?>" class="post-title" rel="bookmark"><?php the_time('d.m.Y') ?>&nbsp;-&nbsp;<?php the_title(); ?></a></h2>
                                                    <div class="post-contents">
                                                            <div class="post-content"><?php the_content('Continua...&raquo;'); ?></div>
                                                    </div><!--[post contents]-->
                                            </div><!-- [post] -->
                                    <?php endwhile; ?>
                                            <div class="navigation">
                                              <span class="previous-entries"><?php next_posts_link('Articoli precedenti...') ?></span><span class="next-entries"><?php previous_posts_link('Articoli successivi...') ?></span>
                                    <?php else : ?>
                                            <span class="center">Mi dispiace, ma non sono presenti articoli in questa pagina.</span>
                                    <?php endif; ?>
                    </div><!-- [box model] -->
            <?php get_sidebar(); ?>
    </div><!-- [centerpiece] -->
    <?php get_footer(); ?>

    and since I don’t use the single page but templates and when I write posts I associate them to categories (except categories 24 and 44 which are only for sticky boxes) which are shown by template pages, but at home page when I click on previous entries (“Articoli precedenti” in the code) or next entries (“Articoli successivi” in the code) it doesn’t shown other posts, looks like it shows same posts…
    Any suggest would be really appreciated…

    Thanks in advance to everyone!!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi,

    Refer this article:

    Also check with this plugin:


    Shane G.

    With two loops not too sure that you will get accurate pagination, but this should work in that 2nd loop:

    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    'category__not_in' => array(24, 44),

    Thanks MichaelH,

    now it works!!! it was that thing of $paged you suggested… what’s that $paged and get_query_var() for?… just a little explanation to understand..

    Thanks again, you saved me hours of work 😉

    That’s the variable WordPress uses to keep track of pagination and the get_query_var returns the value of that variable.

    And why it does need to pass to $args this ‘paged’ parameter when next_post_link(…) should retrieve automatically n more recently chronological posts even if in templates but when they are just POSTS anyway?….

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Query_posts loop and pagination’ is closed to new replies.