Support » Fixing WordPress » Query_posts loop and pagination

  • Resolved Luigino

    (@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">
                                    <?php
                                            $category = get_the_category(''); $cat_slug = $category[0]->category_nicename;
                                            query_posts('tag=welcome');
                                            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();
                                    ?>
                            </div>
                    </div>
                    <?php else : ?>
                    <?php endif; ?>
                    <div id="boxmodel_main">
                            <div id="content">
                                    <?php
                                    if (!is_single()) :
                                            $args=array(
                                                    'category__not_in' => array(24, 44),
                                                    'caller_get_posts'=>1
                                            );
                                            query_posts($args);
                                    endif;
                                    ?>
                                    <?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><!--[post-blocktitle]-->
                                                    </div>
                                                    <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>
                                            </div>
                                    <?php else : ?>
                                            <span class="center">Mi dispiace, ma non sono presenti articoli in questa pagina.</span>
                                    <?php endif; ?>
                            </div><!--[content]-->
                    </div><!-- [box model] -->
            </div>
            <?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!!
    Ciao,
    Luigi

Viewing 5 replies - 1 through 5 (of 5 total)
  • Shane G

    (@shane-g)

    Hi,

    Refer this article:

    http://codex.wordpress.org/Next_and_Previous_Links

    Also check with this plugin:

    http://wordpress.org/extend/plugins/wp-paginate/

    Thanks,

    Shane G.

    MichaelH

    (@michaelh)

    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;
    $args=array(
    'category__not_in' => array(24, 44),
    'caller_get_posts'=>1,
    'paged'=>$paged
    )

    Luigino

    (@luigino)

    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 😉
    Luigi

    MichaelH

    (@michaelh)

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

    Luigino

    (@luigino)

    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.