My image galleries are showing only one thumbnail in the post the gallery sits in. http://themeforward.com/demo2/2013/03/08/image-gallery/

My single.php markup can be found here: http://snippi.com/s/akm5jb7

Additionally, previous_image_link and next_image_link are not displaying when the image is clicked (these would lead to the other images in the gallery).

My entire image.php markup can be found here: http://snippi.com/s/ajwa5yh

My gallery shortcode: [gallery link="post" ids="2245,2246,2247"]

  • 1
    What is the code in setPostViews() function? Mar 11, 2013 at 4:45
  • Forgive me if I'm completely missing something but these two source codes don't appear to be the same. Are you linking us to the correct file? I lack the rep points to post images so here's a link instead. Mar 11, 2013 at 6:13
  • That is for a post views counter which does not impact this question. Mar 11, 2013 at 6:34
  • Is this with WP3.5? Can you go into the text mode of the post edit screen and paste the gallery shortcode into your question? Mar 11, 2013 at 12:39
  • Question updated. Mar 12, 2013 at 0:05

2 Answers 2


Try this and verify that the attachments come back correctly when queried directly:

// helper function to return first regex match
function get_match( $regex, $content ) {
    preg_match($regex, $content, $matches);
    return $matches[1];

// Extract the shortcode arguments from the $post
$shortcode_args = shortcode_parse_atts(get_match('/\[gallery\s(.*)\]/isU', $post->post_content));

// get the attachments specified in the "ids" shortcode argument
$attachments = get_posts(
        'include' => $shortcode_args["ids"], 
        'post_status' => 'inherit', 
        'post_type' => 'attachment', 
        'post_mime_type' => 'image', 
        'order' => 'menu_order ID', 
        'orderby' => 'post__in', //this forces the order to be based on the order of the "include" param

echo 'gallery count:' . count( $attachments );

If that count is correct, then the gallery shortcode should be returning correctly. Let me know what that returns.

  • Where do I place this? Mar 12, 2013 at 13:54
  • drop that in your page template to see if it spits out the correct count of attachments in the gallery which should be 3 given your example of [gallery link="post" ids="2245,2246,2247"]
    – anderly
    Mar 12, 2013 at 13:57
  • It returned "gallery count:1" Mar 12, 2013 at 14:14
  • Ok, in that case, it sounds like there is truly only one attachment. Can you verify whether or not those other attachment ids actually exist under Media? Or if you have access to the db via phpMyAdmin, you could query the post table directly for those IDs. One other way to check for their existence is to see if you can get to these URLs: /wp-admin/post.php?post=2245&action=edit /wp-admin/post.php?post=2246&action=edit /wp-admin/post.php?post=2247&action=edit
    – anderly
    Mar 12, 2013 at 19:12
  • Yes, they exist and they are attached to the appropriate post. Mar 12, 2013 at 20:26

It ended up being a problem with a code to pull a custom number of posts via an options panel.

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.