WordPress provides attachment pages out of the box. But is it somehow possible to have page with listing of all attachments that are connected to a certain post? It should basically work as a gallery overview. So this is not to be on the post page, but on its own.


You can. I think, you should do that with page-template. For that, create a page template. Easiest way is:

1) Inside your theme folder, make a duplicate of page.php and name it i.e. my-page.php

2) open that file and in the top, after <?php place this:

* Template Name: my templt for attchmnts

3) then just remove the content <div> (you should determine that area) and place this code:

$attachments = get_posts( array(
    'post_type' => 'attachment',
    'parent'    =>  $_GET['post_id'],
) );

foreach ( $attachments as $each ) {
    echo 'Title is:' . $each->post_title . ' [content is]: ' . $each->post_content ."<br/><br/>";

(This is just a skeleton, you should build other things yourself.)

then open a new page (i.e. exmaple.com/my_pageee) and choose that template while publishing the page (under PUBLISH button). Then you should access that page like this:


so, you will get all attachments for post 436

  • that's cool Tazo! Can you do it with CPT fields too?
    – rudtek
    Oct 7 '16 at 22:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.