• I use this code:

    <?php
    				// set the "paged" parameter (use 'page' if the query is on a static front page)
    				$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
    
    				// the query
    				$the_query = new WP_Query( 'cat=2&showposts=4&paged=' . $paged );
    				?>
    
    				<?php if ( $the_query->have_posts() ) : ?>
    
    				<?php
    				// the loop
    				while ( $the_query->have_posts() ) : $the_query->the_post();
    				?>
    
    blablabla
    				<?php endwhile; ?>
    
    				<?php
    
    					//wp_query is the gloabal var. If you put this in function remember to globalize var using: global $wp_query
    					$total_pages = $the_query->max_num_pages;
    					if ($total_pages > 1) {
    						$current_page = get_query_var('paged') ? get_query_var('paged') : 1;
    						echo paginate_links(array(
    							'base'         => add_query_arg('paged','%#%'),	//base url
    							'format'       => '',							//replaces the %_% above
    							'total'        => $total_pages,					//total num pages
    							'current'      => $current_page,				//current page
    							'show_all'     => False,						//show all the pages available
    							'end_size'     => 1,							//how many pages at the ends
    							'mid_size'     => 2,							//how many pages around the current page
    							'prev_next'    => true,						//show prev and next buttons
    							'type'         => 'list',						//plain, array, list
    							'prev_text'    => __('? Back'),
        							'next_text'    => __('Next ?'),
    						));
    					}
    
    				?>
    
    				<?php
    				// clean up after our query
    				wp_reset_postdata(); ?>
    				<?php else:  ?>
    				<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
    				<?php endif; ?>

    It works great if I have more then 4 posts. If I have two, for example, I see – Sorry, no posts matched your criteria.

    How can I change this?

    Thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • Well.. you’re only conditionally checking IF there is more than one page returned do this… ELSE echo “Sorry”.

    But.. what happens if JUST one page is returned? It’s going to fall into the ELSE conditional… returning “Sorry”.

    You need to declare an IF/ELSE to set what happens if just one page is returned.

    Thread Starter nickgugu

    (@nickgugu)

    Thanks for reply

    I understand but I don’t know how ??

    What I need to write if posts < post of the page

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to change show post per page in category-ID.php’ is closed to new replies.