Display posts and gallery of post attachments seperately
I was inspired to tackle this after seeing Ma.tt’s Gallery collection.
I wanted to keep the post and the images together in the same post, but I want to display the posts and the gallery separately. I have large blog posts with 10-40 images for each post. I can’t just add the
[gallery]shortcode tag at the end of the post, it would be absurdly long.
Ma.tt gets away with it easily as he publishes his images and posts separately. That wasn’t an option for me. With some customizations to my single.php template I was able to display my post and my gallery separately by using a variable in my URL.
Single Post (Only post, no gallery):
Single Post (Only galley, no post)
You will notice the only difference between the two URLs is the last variable
?att=yesadded to the end of the gallery URL.
In my single.php I replaced
<?php the_content(__('Continue Reading »')); ?>
<?php $att = $_GET["att"]; if ($att=="yes") echo do_shortcode('[gallery]'); else echo the_content(__('Continue Reading »')); ?>
do_shortcode('[gallery]'), it essentially is the same as creating a post what the gallery shortcode in it. See http://codex.wordpress.org/Using_the_gallery_shortcode
I then created a category specific template for my category “Gallery”. In this Gallery template I have my code that displays a photo and post related info for each post with the Gallery category. See http://codex.wordpress.org/Category_Templates#What_Template_File_is_Used.3F
I modified the code so that every time the image and title is linked, the link contains ?att=yes at the end of the href URL.
Cade example for the linked highlight image:
<a href="<?php the_permalink(); ?>?att=yes"><?php echo $thePic; ?></a>
For every post that I attach images to and want to have a album displayed in my gallery I simply add the Gallery category to it.
A few things I am working to improve:
-Add album navigation (next album, previous album, back to gallery)
-I would like to turn the variable ?att=yes to just /gallery/ at the end of the URL.
-Add View Post and View Gallery links to the post (possibly AJAXed)
- The topic ‘Display posts and gallery of post attachments seperately’ is closed to new replies.