Title: Does &#8220;paginate_links&#8221; function work for attachment.php ?
Last modified: April 5, 2018

---

# Does “paginate_links” function work for attachment.php ?

 *  [Optic](https://wordpress.org/support/users/optic/)
 * (@optic)
 * [8 years, 1 month ago](https://wordpress.org/support/topic/does-paginate_links-function-work-for-attachment-php/)
 * Hi there,
 * Hope you’re doing well.
 * I am looking to add pagination for my attachment pages.
    – e.g. << Prev 1 | 2
   | 3 | 4 | 5 | 6 Next >>
 * The use case would be for displaying a comic, so users can browse through each
   page using pagination (I prefer to use attachment pages in order to display the
   attachment captions and metadata).
 * I have already added previous/next image thumbnail links by using **next_image_link**
   and **previous_image_link**.
 * Can you advise the best function for adding pagination number links? Similar 
   to pagination in category archives?
 * I had a browse and came across paginate_links:
    [https://codex.wordpress.org/Function_Reference/paginate_links](https://codex.wordpress.org/Function_Reference/paginate_links)
 * Would that work within attachment.php ?
 * Any help or guidance would greatly be appreciated, thank you.

Viewing 1 replies (of 1 total)

 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [8 years, 1 month ago](https://wordpress.org/support/topic/does-paginate_links-function-work-for-attachment-php/#post-10150665)
 * paginate_links() will only work for archive type queries. An attachment query
   is typically most like a single post query. As such, it’s not logical for there
   to be page numbers because there are not pages of results. The numbers you want
   to assign are more abstract, more like a panel sequence number than a page number.
 * For page numbering to work, you would need to make a a query for all image attachments
   of a post, with the posts per page argument set to 1. This will result in an 
   archive template being used, not the attachment template, defeating your objective.
   However, if you were to make a copy of your attachment template file and name
   it archive-attachment.php, you should get the display style you want with an 
   attachment archive query. With such a query, paginate_links() will work.
 * I’m not sure what URL would result in a post’s all images query, but in theory
   any query can be converted to any other query by using the “pre_get_posts” filter.
   There may be a lot of query arguments that need to be changed.

Viewing 1 replies (of 1 total)

The topic ‘Does “paginate_links” function work for attachment.php ?’ is closed to
new replies.

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 1 reply
 * 2 participants
 * Last reply from: [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * Last activity: [8 years, 1 month ago](https://wordpress.org/support/topic/does-paginate_links-function-work-for-attachment-php/#post-10150665)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
