Need help? Check out our Support site, then


Pagination not working on page of posts

  1. Hi

    I've created a custom page display posts for a specific category. But the pagination doesn't work. When you click on "next" the link looks like this: http://localhost:8080/meles/page/2/ but it's still displaying the same posts as on the first page. Can anybody please help???

    My code looks like this:
    <?php
    /*
    Template Name: PageOfPosts
    */

    get_header(); ?>

    <div id="page-content" class="narrowcolumn">

    <?php

    $cat = 1;
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $post_per_page = 2; // -1 shows all posts
    //$do_not_show_stickies = 1; // 0 to show stickies
    $args=array(
    'category__in' => array($cat),
    'orderby' => 'date',
    'order' => 'DESC',
    'paged' => $paged,
    'showposts' => $post_per_page
    //'caller_get_posts' => $do_not_show_stickies
    );
    $temp = $wp_query; // assign orginal query to temp variable for later use
    $wp_query = null;
    $wp_query = new WP_Query($args);

    if( have_posts() ) :
    while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
    <div id="post-<?php the_ID(); ?>" class="homepage-posts">
    <h2>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></h2>

    <?php
    $images = get_children( array( 'post_parent' => $post->ID, 'post_type' => 'attachment', 'post_mime_type' => 'image', 'orderby' => 'menu_order', 'order' => 'ASC', 'numberposts' => 999 ) );
    if ( $images ) :
    $total_images = count( $images );
    $image = array_shift( $images );
    $image_img_tag = wp_get_attachment_image( $image->ID, 'thumbnail' );
    ?>
    <div class="homepage-thumb">
    "><?php echo $image_img_tag; ?>
    </div><!-- .gallery-thumb -->
    <div class="homepage-summary">
    <?php the_excerpt( __( 'Read more <span class="meta-nav">→</span>', 'twentyten' ) ); ?>
    <?php wp_link_pages( array( 'before' => '<div class="page-link">' . __( 'Pages:', 'twentyten' ), 'after' => '</div>' ) ); ?>
    </div><!-- .entry-content -->
    <?php else : ?>
    <div class="homepage-summary-full">
    <?php the_excerpt( __( 'Read more <span class="meta-nav">→</span>', 'twentyten' ) ); ?>
    <?php wp_link_pages( array( 'before' => '<div class="page-link">' . __( 'Pages:', 'twentyten' ), 'after' => '</div>' ) ); ?>
    </div><!-- .entry-content -->
    <?php endif; ?>

    </div>
    <?php endwhile; ?>

    <div class="navigation">
    <div class="alignright"><?php previous_posts_link('Newer Entries »') ?></div>
    <div class="alignleft"><?php next_posts_link('« Older 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 get_search_form(); ?>

    <?php endif;

    $wp_query = $temp; //reset back to original query

    ?>

    </div>

    <?php get_sidebar(); ?>

    <?php get_footer(); ?>

  2. No we can't really help you here, but we can suggest where you can get the help you need.

    Your site is not hosted on WordPress.COM, this site is for support of sites hosted on WordPress.COM. You should address your questions to WordPress.ORG the keepers of the software you are using: http://wordpress.org/support/

    For more on the difference: http://support.wordpress.com/com-vs-org/

  3. thank you

Topic Closed

This topic has been closed to new replies.

About this Topic