defsounds

http://revisedagain.com/wp-content/themes/r

Full Gallery In WordPress Attachment Page

Posted on March 24th, 2011 Full Gallery In WordPress Attachment Page

The simplest answers are often the hardest to find. This couldn’t be truer (is that actually a word?..truer?..because if it is, wronger should be one too and so should be truiest and wrongiest)..anyways–A client needed a standard gallery–nothing fancy. Just a big image and a bunch of little images from that same gallery.

Instead of resorting to a plugin, I decided to hack away at the attachment.php page.  If you’re using the Twentyten theme as a skeleton for your own, you’ll have to edit loop-attachment.php.

The easiest way to do this is to use WordPress’s builtin gallery shortcode.

  
  1. [gallery id=ID]

But how can we use this outside of our posts?…By using WordPress’s do_shortcode php function.

  
<?php echo do_shortcode("
[gallery id]
"
); ?>

One more problem, how to make this dynamic so that the Gallery shown is the one the attachment belongs to? Do the following:

  
<?php echo do_shortcode("[gallery id=$post->post_parent columns=6]");?>

The columns setting doesn’t have to be specified but it’s good for styling.

5 Comments for Full Gallery In WordPress Attachment Page



steve

can you help me?
im trying to have caption and image name under gallery thumbnails

Jay

You’ll have to edit the gallery short code in media.php or add your own to your themes functions.php file

Jaxon

Yo, good looikn out! Gonna make it work now.

Idella Murphree

A Great job once again!! I am looking forward for your next post!

cruises from baltimore

Hello! I just wanted to ask if you ever have any issues with hackers? My last blog (wordpress) was hacked and I ended up losing a few months of hard work due to no data backup. Do you have any solutions to stop hackers?



Leave a comment