WordPress.org

Ready to get started?Download WordPress

Forums

Paging is just showing the repeat of first page posts (2 posts)

  1. vikkineal
    Member
    Posted 7 months ago #

    Hi can anyone help?

    I've set up category-5.php to show all posts assigned to it and none of category-4.php posts.

    The trouble is that the paging doesn't seem to be working - not sure if that's related or not - but it's only showing the same set of posts (that are in category 4).

    Any ideas what I'm doing wrong?

    Thank you :)

    <?php get_header(); ?>
    
    <div class="clearBoth"></div>
    <div class="container clearFix">
    <div class="articles">
      <?php
    $args = array( 'category_name' => 'Project Portfolio' );
    $lastposts = get_posts( $args );
    foreach($lastposts as $post) : setup_postdata($post); ?>
      <div class="grid_5">
        <a href="<?php the_permalink(); ?>">
        <?php the_post_thumbnail('portfolio-category'); ?>
        </a>
      </div>
      <div class="grid_7">
        <h3><?php the_title(); ?></h3>
        <p><?php the_excerpt(0,200); ?></p>
        <p><a href="<?php the_permalink(); ?>">Read more</a></p>
      </div>
      <div class="clearBoth"></div>
      <hr />
      <?php endforeach; ?>
    </div>
    <div class="paging">
      <?php posts_nav_link('&nbsp;','<','>'); ?>
    </div>
    <?php get_footer(); ?>
  2. vtxyzzy
    Member
    Posted 7 months ago #

    The posts_nav_link() function depends on $wp_query being set by a query. It will not work for an array such as your $lastposts.

    One solution is to use the WP function paginate_links() as described in this article: http://wordpress.mcdspot.com/2010/11/25/pagination-using-paginate_links/

Reply

You must log in to post.

About this Topic