Title: Loop with pagination
Last modified: August 20, 2016

---

# Loop with pagination

 *  [zara](https://wordpress.org/support/users/zarafourcommunications/)
 * (@zarafourcommunications)
 * [13 years, 9 months ago](https://wordpress.org/support/topic/loop-with-pagination/)
 * I have a loop i need a little help with adding pagination to it so it display
   6 posts per page.
 *     ```
       <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
   
       	<div  <?php post_class(); ?> id="post-<?php the_ID(); ?>">
       		<h1><?php the_title(); ?></h1>
       		<?php
       $attachments = get_children(array('post_parent' => $post->ID,
       						'post_status' => 'inherit',
       						'post_type' => 'attachment',
       						'post_mime_type' => 'image',
       						'order' => 'ASC',
       						'orderby' => 'menu_order ID'));
   
       foreach($attachments as $att_id => $attachment) {
       	$full_img_url = wp_get_attachment_url($attachment->ID);
               $split_pos = strpos($full_img_url, 'wp-content');
               $split_len = (strlen($full_img_url) - $split_pos);
               $abs_img_url = substr($full_img_url, $split_pos, $split_len);
               $full_info = @getimagesize(ABSPATH.$abs_img_url);
       		$img_desc = $attachments->post_excerpt;
               ?>
   
       			<a class="popupimage" href="<?php echo $full_img_url; ?>" title="<?php echo $attachment->desc ; echo $attachment->post_content; ?>" target="_blank"><img  src="<?php echo $full_img_url; ?>" /></a>
   
       <?php
       }
       ?>
   
       		<?php the_content(); ?>
       	</div>
   
       <?php endwhile; ?>
   
       	<div class="navigation">
       		<div class="next-posts"><?php next_posts_link(); ?></div>
       		<div class="prev-posts"><?php previous_posts_link(); ?></div>
       	</div>
   
       <?php else : ?>
   
       	<div <?php post_class(); ?> id="post-<?php the_ID(); ?>">
       		<h1>Not Found</h1>
       	</div>
   
       <?php endif; ?>
       ```
   

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [13 years, 9 months ago](https://wordpress.org/support/topic/loop-with-pagination/#post-2949762)
 * set the number 6 under
    _**dashboard – settings – reading**_ – _Blog pages show
   at most [ 6 ] posts_
 * the code for the ‘nextposts/previous posts’ is already in the posted section.
 * what template file is that, and what does it show now?
 *  Thread Starter [zara](https://wordpress.org/support/users/zarafourcommunications/)
 * (@zarafourcommunications)
 * [13 years, 9 months ago](https://wordpress.org/support/topic/loop-with-pagination/#post-2949763)
 * Thanks That worked I am new to WordPress just started new job and and first task
   build site in WordPress just having a few little glitches to fix.
 * Thanks
 * Again

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Loop with pagination’ is closed to new replies.

## Tags

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [zara](https://wordpress.org/support/users/zarafourcommunications/)
 * Last activity: [13 years, 9 months ago](https://wordpress.org/support/topic/loop-with-pagination/#post-2949763)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
