I have several custom post types similar to (place, person,etc.) refer this and under each of these custom post type there are several posts inserted. (ex.http://www.firstpost.com/topic/person/amitabh-bachchan-profile-5605.html)

Each post will be having the image attachments out of which I want to create a gallery page similar to this.

Currently I have progressed to generate a single page for each custom post type. can anyone please advise me for the further process?


You can consider the following link: www.newsmirror.agstechnologies.com/topic/place/new-delhi

see the link "View All" on the top right part of the gallery. For the time I have created a normal page and I am passing the ID of the post as the parameter to that page and using that ID I am fetching the attachment images for that post.

but that crates URL something like www.newsmirror.agstechnologies.com/gallery?id=322

but I want the link like: www.newsmirror.agstechnologies.com/topic/place/new-delhi/gallery

can anybody help me on this?

Sorry but I cannot post the direct links so you have to copy paste the URLS.

2 Answers 2


If you want to get all images attached to a single post then you can use this

if ( $images = get_posts(array(
'post_parent' => $post->ID,
'post_type' => 'attachment',
'numberposts' => -1,
'post_mime_type' => 'image',)))
foreach( $images as $image ) {
$attachmentimage=wp_get_attachment_image_src( $image->ID, full );
$imageDescription = apply_filters( 'the_description' , $image->post_content );
$imageTitle = apply_filters( 'the_title' , $image->post_title );

    if (!empty($imageDescription)) {
    echo '<a href="'.$imageDescription .'"><img src="' . $attachmentimage[0] . '" alt=""     /></a>';
    } else { echo '<img src="' . $attachmentimage[0] . '" alt="" />'; }

} else {
echo "No Image";

check also this link http://wordpress.org/support/topic/get-images-attached-to-posts-no-problem-but-need-to-remove-the-featured-image


Try using gallery_shortcode() function, that powers native [gallery] shortcode. It accept plenty of args and generates (semi-)usable resulting markup that can be further customized and/or styled.

  • can you please suggest something like creating a virtual page which wraps the gallery of images for post? and create a link through which I will be able to visit the gallery? Preserving the URL is most important for me. Oct 15, 2012 at 10:54
  • @Rohit Pande what you want to achieve there sounds like rewrite endpoint (see add_rewrite_endpoint()) but it's not quite my area so not sure.
    – Rarst
    Oct 15, 2012 at 18:35
  • Thanks for the reply. Please refer to the details in question again. I have edited it and provided the exact scenario. Please see if u can help me out. Oct 16, 2012 at 9:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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