WordPress.org

Ready to get started?Download WordPress

Forums

Pagination not working on page of posts (1 post)

  1. Elmarie
    Member
    Posted 3 years ago #

    I've created a custom page to display posts from 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(); ?>

Topic Closed

This topic has been closed to new replies.

About this Topic