The Support Forums will be in read-only mode for a scheduled maintenance window on 01 September 2016 14:00 UTC - 20:00 UTC. More information.

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

  1. vikkineal
    Posted 2 years 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">
    $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'); ?>
      <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 class="clearBoth"></div>
      <hr />
      <?php endforeach; ?>
    <div class="paging">
      <?php posts_nav_link('&nbsp;','<','>'); ?>
    <?php get_footer(); ?>
  2. vtxyzzy
    Posted 2 years 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/

Topic Closed

This topic has been closed to new replies.

About this Topic