[resolved] paginate links not working!! help! (3 posts)

  1. joyceliu6
    Posted 3 years ago #

    I want to create a news page displaying only 3 posts per page and if there are 5 posts the last two posts will display on the second page.
    Here is what I have got so far...

    <?php query_posts('category_name=news&&showposts=3'); ?>
    	<?php while (have_posts()) : the_post(); ?>
    	<div class="tpost-whole">
    	<hr /> <!--creates spaces between each posts-->
    		<div class="post-thumbnail">
    			<?php if ( has_post_thumbnail()) : ?>
    			<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >
    			<?php the_post_thumbnail('thumbnail');?>
    			<?php endif; ?>
    		<div class="tpost-title">
              		<h3><a class="tpost-title" href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" ><?php the_title(); ?></a></h3>
    	<span class="post-date"><?php the_time('F j, Y') ?></span><br />
     	<?php echo apply_filters('the_excerpt',get_the_excerpt().'<a href="'.get_permalink().'"> read more </a>'); ?>
    	<hr /> <!--creates spaces between each posts-->
    	<?php endwhile; ?>			
    <?php echo paginate_links( $args ) ?>
    global $wp_query;
    $big = 999999999; // need an unlikely integer
    echo paginate_links( array(
    	'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
    	'format' => '?paged=%#%',
    	'current' => max( 1, get_query_var('paged') ),
    	'total' => $wp_query->max_num_pages
    ) );

    The problem is when I clicked to the second page it doesn't display the last two posts. It still display the first 3 posts.
    Please help me! Thanks

  2. IMICreation
    Posted 3 years ago #

    replace this line with
    <?php query_posts('category_name=news&&showposts=3'); ?>
    <?php query_posts(array('category_name'=>'news','posts_per_page'=>'3','paged' => get_query_var('paged'))); ?>
    and reset query after endwhile with
    <?php wp_reset_query(); ?>

  3. joyceliu6
    Posted 3 years ago #

    It's working now!!
    Thank you so much :)

Topic Closed

This topic has been closed to new replies.

About this Topic