Support » Themes and Templates » pagination problem

  • Hi, I want to create pagination for a page that show 3 posts
    That’s the code I have:

    <?php query_posts('showposts=3'); while (have_posts()) : the_post(); ?>
    <li class="noticias"><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></li>
    <?php get_posts(); ?>
    <?php endwhile; ?>

    What I want would be something like this:

    • Article 1
    • Article 2
    • Article 3

    < Previous 3 items | Next 3 Items >

    Any Idea?

Viewing 3 replies - 1 through 3 (of 3 total)
  • You’d need to use offset to offset where the posts start displaying…

    You could check using GET, if get has been set then set an offset, if none then don’t set one…

    Something like this…

    if(isset($_GET['step'])) {
        if($_GET['step'] == '3') {
            $some_offset = '&offset=3';
        } else if($_GET['step'] == '6') {
            $some_offset = '&offset=6';
        } else {
            $some_offset = '';
    } elseif(!isset($_GET['step'])) {
        $some_offset = '';

    Then in your query you add $some_offset … like so…

    <?php query_posts('showposts=3'.$some_offset.'');

    Then create your page links, just adding ?step=3 to set the offset to 3, or ?step=6 to set the offset to 6.

    And so on…

    The above example is very basic and crude, you can of course edit it and do as you choose. There are many ways to handle it, and i’m sure there’s proberly a much better way to do the above using built in WP functionality.

    I’d suggest reading the function docs in the Codex or waiting to see if a seasoned WP user can suggest something more WP function orientated.

    Wow t31os!
    Works perfectly, now I’ll try to add some ajax functionality, thanks a lot!

    One more thing.
    If I put this as new and old page links:

    <a href="&offset=3"><p>New</p></a>
    <a href="&offset=-3)"><p>Old</p></a>

    I only get just the 3 previous and 3 next articles, How can I do to get the next 3 ant the previous 3 on every page reload?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘pagination problem’ is closed to new replies.