WordPress.org

Ready to get started?Download WordPress

Forums

WP-PageNavi
pagination leads me to 404 error page (1 post)

  1. iversoncru
    Member
    Posted 1 year ago #

    hi there
    here is my code to show posts by month and year, but only to show 2 posts per page, but the pagination with WP-PageNavi is not working.

    <article>
    	<?php
    		$url = curPageURL();
    		$yearMonth = substr($url, strrpos($url, '/') - 7, 7);
    		$year = substr($yearMonth, 0, 4);
    		$monthnum = substr($yearMonth, 5, 2);
    		$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
    		$temp = $wp_query;
    		$wp_query= null;
    		$wp_query = new WP_Query();
    		$args = array(
    			'monthnum' => $monthnum,
    			'year' => $year,
    			'posts_per_archive_page' => 2,
    			'cat'            => 7,
    			'paged'          => $paged
    		);
    		//var_dump($args);
    		$wp_query->query( $args );
    		while ( $wp_query->have_posts() ) : $wp_query->the_post();
    		//$post_id = get_the_ID();
    	?>
    	<?php
    		$title = get_the_title();
    		if (strlen($title) > 20) {
    			$title = substr($title, 0, 18) . '...';
    		}
    	?>
    	<h2><a href="<?php the_permalink(); ?>"><?php echo $title; ?></a>   <?php the_time('F jS, Y') ?></h2>
    	<?php the_post_thumbnail('thumbnail');?>
    
    	<p><?php
    		$excerpt = get_the_excerpt();
      		echo string_limit_words($excerpt,56);
    	?></p>
    	<p class="read_more">Read the full post <a href="<?php the_permalink(); ?>">here</a></p>
    	<?php endwhile;
    		//wp_pagenavi( array( 'query' => $wp_query ) );
    		wp_pagenavi( array( 'type' => 'multipart' , 'query' => $wp_query) );
    		//wp_pagenavi();
    		/*$page_navi = function_exists('wp_pagenavi') ? true : false ;
    		($page_navi) ? wp_pagenavi() : posts_nav_link();*/
    	?>
    	<?php wp_reset_postdata(); ?>
    	<?php $wp_query = null; $wp_query = $temp; ?>
    </article>

    I can see the pagination, but when i click to go to the next page, it leads me to 404 error page...

    i have tried the pieces of code which are commented, below endwhile;

    <?php endwhile;
    	//wp_pagenavi( array( 'query' => $wp_query ) );
    	wp_pagenavi( array( 'type' => 'multipart' , 'query' => $wp_query) );
    	//wp_pagenavi();
    	/*$page_navi = function_exists('wp_pagenavi') ? true : false ;
    	($page_navi) ? wp_pagenavi() : posts_nav_link();*/
    ?>

    neither of them work...

    This is the second time i use this plugin in my website. It is working perfectly for my blog. But not here...(archive.php)

    any ideas?

    thanks in advance for yout time!

    http://wordpress.org/extend/plugins/wp-pagenavi/

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic