Display posts and gallery of post attachments seperately
-
I was inspired to tackle this after seeing Ma.tt’s Gallery collection.
https://ma.tt/category/gallery/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.
-Example-
Single Post (Only post, no gallery):
https://www.karieandscott.com/blog/the-running-of-the-crazy-people-oh-yeah-and-bulls
Single Post (Only galley, no post)
https://www.karieandscott.com/blog/the-running-of-the-crazy-people-oh-yeah-and-bulls?att=yesYou will notice the only difference between the two URLs is the last variable
?att=yes
added to the end of the gallery URL.In my single.php I replaced
<?php the_content(__('Continue Reading ?')); ?>
with
<?php $att = $_GET["att"]; if ($att=="yes") echo do_shortcode('[gallery]'); else echo the_content(__('Continue Reading ?')); ?>
By using
do_shortcode('[gallery]')
, it essentially is the same as creating a post what the gallery shortcode in it. See https://codex.www.ads-software.com/Using_the_gallery_shortcodeI 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 https://codex.www.ads-software.com/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>
My Gallery
https://www.karieandscott.com/blog/category/galleryFor 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)My Blog
https://www.karieandscott.com/blog
My Gallery
https://www.karieandscott.com/blog/category/galleryScott Kaufmann
- The topic ‘Display posts and gallery of post attachments seperately’ is closed to new replies.