Title: Search.php With Pagination Coding
Last modified: August 21, 2016

---

# Search.php With Pagination Coding

 *  [startam](https://wordpress.org/support/users/startam/)
 * (@startam)
 * [12 years, 8 months ago](https://wordpress.org/support/topic/searchphp-with-pagination-coding/)
 * Hello everyone,
 * I’m in need of some simple help. The coding for my search.php is not producing
   the correct url for the pagination. Currently, the coding is producing the following
   when you click on the pagination.
 * [http://website.com/?s=topic/page/2/](http://website.com/?s=topic/page/2/)
 * It should be producing this:
 * [http://website.com/page/2/?s=topic/](http://website.com/page/2/?s=topic/)
 * Can anyone help me figure out what is wrong with the coding.
 *     ```
       <?php get_header(); ?>
       <div id = "left-side-content">
   
       <div id = "ls_title">
       <div id = "sub_title_cat">Search Results</div>
       </div>
   
       <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
       <div id = "blog_post">
       <div id = "blog_thumb"><img src="<?php echo catch_that_image() ?>" width = "100%"></div>
       <div id = "blog-post-column">
       <div id = "post_title"><?php the_category(', '); ?></div>
       <div id = "post_sub_title"><a>"><?php the_title(); ?></a></div>
       <div id = "post_desc"><?php echo wp_trim_excerpt(); ?></div>
       <span class = "post_readmore"><a>">Unplug More</a></span>
       </div>
       </div>
   
       <?php endwhile; ?>
       <div id = "title_cat">{
       <?php global $wp_query;
       $total_pages = $wp_query->max_num_pages;
   
       if ($total_pages > 1){
       $current_page = max(1, get_query_var('paged'));
         echo paginate_links(array(
       	  'base' => get_pagenum_link(1) . '%_%',
       	  'format' => '/page/%#%/',
             'current' => $current_page,
             'total' => $total_pages,
       	  'prev_next'    => True,
           ));  
   
       }
       ?>}
       <?php else : ?>
   
       <div id = "title_cat">
       	<div <?php post_class(); ?> id="post-<?php the_ID(); ?>">
       		<h1>Not Found</h1>
       	</div>
       <?php endif; ?>
       </div>
       ```
   
 * _[Moderator Note: Please post code or markup between backticks (not single quotes)
   or use the code button. Or better still – use a [pastebin](http://pastebin.com/).
   Your posted code may now have been permanently damaged by the forum’s parser.]_
 * Thank you,

Viewing 1 replies (of 1 total)

 *  Thread Starter [startam](https://wordpress.org/support/users/startam/)
 * (@startam)
 * [12 years, 8 months ago](https://wordpress.org/support/topic/searchphp-with-pagination-coding/#post-4176289)
 *     ```
       <?php get_header(); ?>
       <div id = "left-side-content">
   
       <div id = "ls_title">
       <div id = "sub_title_cat">Search Results</div>
       </div>
   
       <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
       <div id = "blog_post">
       <div id = "blog_thumb"><img src="<?php echo catch_that_image() ?>" width = "100%"></div>
       <div id = "blog-post-column">
       <div id = "post_title"><?php the_category(', '); ?></div>
       <div id = "post_sub_title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></div>
       <div id = "post_desc"><?php echo wp_trim_excerpt(); ?></div>
       <span class = "post_readmore"><a href="<?php the_permalink(); ?>">Unplug More</a></span>
       </div>
       </div>
   
       <?php endwhile; ?>
       <div id = "title_cat">{
       <?php global $wp_query;
       $total_pages = $wp_query->max_num_pages;
   
       if ($total_pages > 1){
       $current_page = max(1, get_query_var('paged'));
         echo paginate_links(array(
       	  'base' => get_pagenum_link(1) . '%_%',
       	  'format' => '/page/%#%/',
             'current' => $current_page,
             'total' => $total_pages,
       	  'prev_next'    => True,
           ));  
   
       }
       ?>}
       <?php else : ?>
   
       <div id = "title_cat">
       	<div <?php post_class(); ?> id="post-<?php the_ID(); ?>">
       		<h1>Not Found</h1>
       	</div>
       <?php endif; ?>
       </div>
       ```
   
 * _[Moderator Note: Please post code or markup between backticks or use the code
   button. Or better still – use a [pastebin](http://pastebin.com/). Your posted
   code may now have been permanently damaged by the forum’s parser.]_

Viewing 1 replies (of 1 total)

The topic ‘Search.php With Pagination Coding’ is closed to new replies.

## Tags

 * [pagination](https://wordpress.org/support/topic-tag/pagination/)
 * [php](https://wordpress.org/support/topic-tag/php/)
 * [search.php](https://wordpress.org/support/topic-tag/search-php/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 1 participant
 * Last reply from: [startam](https://wordpress.org/support/users/startam/)
 * Last activity: [12 years, 8 months ago](https://wordpress.org/support/topic/searchphp-with-pagination-coding/#post-4176289)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
