Custom loop pagination
-
Hi guys, I’ve looked everywhere for a solution to this but still must be doing something wrong!
I have set up a page template with a custom loop to show my post thumbnails on my front page which seems to work fine, however I cannot get the pagination to work correctly.
Currently the ‘older entries’ link works but still displays even when there are no older posts, and the ‘Newer Entries’ never shows at all!
My code is as follows:
<?php /* Template Name: Portfolio */ ?> <?php get_header(); ?> <div id="content"> <?php $page = get_query_var( 'page' ); query_posts( array('category_name' => 'portfolio', 'posts_per_page' => 2, 'paged' => $page)); ?> <?php if (have_posts()) : while (have_posts()) : the_post(); ?> <div class="post" id="post-<?php the_ID(); ?>"> <div class="box"> <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"> <?php the_post_thumbnail('portfolio-thumb'); ?> </a> </div> <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2> <div class="entry"> <p>Show project details</a></p> </div> </div> <?php endwhile; ?> <div class="clear"> </div> <div class="navigation"> <div class="alignleft"><?php next_posts_link('← Older Entries') ?></div> <div class="alignright"><?php previous_posts_link('Newer Entries →') ?></div> </div> <?php else : ?> <h2 class="center">Not Found</h2> <p class="center">Sorry, but you are looking for something that isn't here.</p> <?php endif; ?> <?php wp_reset_query(); ?> </div> <?php get_footer(); ?>
Any help greatly appreciated!
Viewing 12 replies - 1 through 12 (of 12 total)
Viewing 12 replies - 1 through 12 (of 12 total)
- The topic ‘Custom loop pagination’ is closed to new replies.