treehouse : what would you like to learn today?
Web Design Web Development iOS Development

Wordpress - pagination

  • I have tried using a few guides for pagination but i can't get any of them to even display the page numbers which i just don't understand... So i have resorted to trying out a plug in, which atleast shows the page numbers, but when you click on page 2 it does nothing. Can anyone either help me get pagination working without this plug in or get this plug in to actually work?

    http://www.lsw-design.com/tf/Gridded/?page_id=8
  • doesn't wordpress have it's own pagination? Have you tried the template tags? if the plugin you are using doesn't work, try a different one. There are lots of them. I don't know how to help you without you giving access to your site. unless you post code
  • <?php get_header(); ?>

    <div id="pagename">
    <div id="pagename-inside">
    <h1>Blog</h1>
    </div>
    </div>


    <div id="blog-inside">

    <?php get_sidebar(); ?>
    <div id="content-blog">

    <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args = array(
    'paged' => $paged,
    'posts_per_page' => 5,
    'caller_get_posts' => 0,
    );
    query_posts('cat=-5');
    if (have_posts()) :
    while (have_posts()) :
    the_post(); ?>

    <div class="post">
    <div class="home-thumb"
    <a class="post-thumb-a" href="<?php the_permalink(); ?>"><?php echo getImage(302,302,"2");?></a>
    <a class="post-thumb-b" href="<?php the_permalink(); ?>"><?php echo getImage(302,302,"");?></a>
    </div>


    <div id="entry">

    <div id="post-date"><span class="post-date"><?php the_time('F j, Y'); ?></span><span class="post-author"> By <?php the_author_meta('nickname'); ?></span><span class="post-comments"><?php comments_popup_link('No Comments', '1 Comment', '% Comments'); ?></span></div>

    <h2 id="post-title"><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>

    <?php the_excerpt(); ?>

    <div class="blog-readmore"><a href="<?php the_permalink(); ?>">Read more &raquo;</a></div>

    </div>
    </div>





    <?php endwhile; else : ?>

    <h2>Woops...</h2>

    <p>Sorry, no posts were found.</p>


    <?php wp_link_pages(); ?>
    <?php endif; ?>




    <?php wp_pagenavi(); ?>
    </div>
    </div>

    <?php get_footer(); ?>



    Thats the code for the blog page, been trying to find answers for pagination since i started learning wordpress and haven't found anything that works, or explains it in detail.



  • in your code, you have query_posts('cat=-5');

    I think it should be query_posts('cat=5');
  • p.s also check out the codex for more on this

    http://codex.wordpress.org/Function_Reference/query_posts
  • If i change it to just 5 no posts show
  • what version of wordpress are you using?
  • also, how many posts do you have in the category?
  • i have 7 posts in the category, and it is the latest version
  • so you see five posts but no pagination?

  • try moving your

    <?php wp_link_pages(); ?>

    up before the

    <?php endwhile; else : ?>

    wp_link_pages must be inside the loop. maybe it's not executing where you have it?
  • tried moving that as well as <?php wp_pagenavi(); ?> to different places, and still not working, if i put it before the endwhile; else then the page numbers show after every post and still doesnt work.
  • at this point, I would try a different loop


    <!-- Start the Loop. -->
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

    <!-- The following tests if the current post is in category 3. -->
    <!-- If it is, the div box is given the CSS class "post-cat-three". -->
    <!-- Otherwise, the div box will be given the CSS class "post". -->
    <?php if ( in_category('5') ) { ?>
    <div class="post-cat-three">
    <?php } else { ?>
    <div class="post">
    <?php } ?>

    <!-- Display the Title as a link to the Post's permalink. -->
    <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>

    <!-- Display the date (November 16th, 2009 format) and a link to other posts by this posts author. -->
    <small><?php the_time('F jS, Y') ?> by <?php the_author_posts_link() ?></small>

    <!-- Display the Post's Content in a div box. -->
    <div class="entry">
    <?php the_content(); ?>
    </div>

    <!-- Display a comma separated list of the Post's Categories. -->
    <p class="postmetadata">Posted in <?php the_category(', '); ?></p>
    </div> <!-- closes the first div box -->

    <!-- Stop The Loop (but note the "else:" - see next line). -->
    <?php endwhile; else: ?>

    <!-- The very first "if" tested to see if there were any Posts to -->
    <!-- display. This "else" part tells what do if there weren't any. -->
    <p>Sorry, no posts matched your criteria.</p>

    <!-- REALLY stop The Loop. -->
    <?php endif; ?>


    try that loop above. You can see the if(in_category(5)) part of the loop. Try it and see if it works. If it does, you can modify it to show the amount of posts that you want
  • that loop showed the posts, but it just done what it was doing before, when i click page 2 it just changes the URL and not the posts.
  • your problem is in here <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args = array(
    'paged' => $paged,
    'posts_per_page' => 5,
    'caller_get_posts' => 0,


    if you check the url after clicking on the two, you can see the address is wrong. I don't know how to fix it for you. Sorry
  • Can anyone else help? Loads of people have done this in their themes, but i can't find an answer for this problem anywhere..
  • okay, I don't know why I didn't think of this earlier, but chris made a tut that will most likely help you figure this out

    http://css-tricks.com/video-screencasts/91-the-wordpress-loop/
  • Thanks, i sorted it out after changing the part you pointed out to something TheDoc posted and it is working now finally. Thanks for your help.
  • Glad to hear it, Luke.

    It really is way more complicated than it should be. But WordPress is still growing into a functioning CMS, I'm sure things like this will get taken care of eventually.
  • what was the problem? Post the sollution for others in the future
  • I changed the part you pointed out to:

    <?php if (have_posts()) : ?>
    <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts("category_name=somecat&paged=$paged"); ?>
    <?php while (have_posts()) : the_post(); ?>