WordPress.org

Forums

Adding Gallery and Album functionality to integrated WordPress Gallery (1 post)

  1. skaufmann
    Member
    Posted 6 years ago #

    I was inspired to tackle this after seeing Ma.tt's Gallery collection.
    http://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):
    http://www.karieandscott.com/blog/the-running-of-the-crazy-people-oh-yeah-and-bulls
    Single Post (Only galley, no post)
    http://www.karieandscott.com/blog/the-running-of-the-crazy-people-oh-yeah-and-bulls?att=yes

    You 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 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)

    My Blog
    http://www.karieandscott.com/blog
    My Gallery
    http://www.karieandscott.com/blog/category/gallery

    Scott Kaufmann

Topic Closed

This topic has been closed to new replies.

About this Topic