WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Query_posts loop and pagination (6 posts)

  1. Luigino
    Member
    Posted 4 years ago #

    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

  2. Shane G
    Member
    Posted 4 years ago #

    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.

  3. MichaelH
    Member
    Posted 4 years ago #

    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
    )
  4. Luigino
    Member
    Posted 4 years ago #

    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

  5. MichaelH
    Member
    Posted 4 years ago #

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

  6. Luigino
    Member
    Posted 4 years ago #

    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?....

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.