Support » Plugins » Display posts and gallery of post attachments seperately

  • I was inspired to tackle this after seeing’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. 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=yes added to the end of the gallery URL.

    In my single.php I replaced

        the_content(__('Continue Reading ยป'));


    <?php $att = $_GET["att"];
        if ($att=="yes")
            echo do_shortcode('[gallery]');
            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

    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

    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

    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
    My Gallery

    Scott Kaufmann

Viewing 13 replies - 1 through 13 (of 13 total)
  • Also to get the gallery category template running, I used the following code:

    I tackled one of my improvements

    -Add View Post and View Gallery links to the post.

    For every post I add the Photo Gallery category to, not only does it add it to the photo gallery page, it also adds a “View Gallery” icon in the upper-right of the post. When you are viewing a post’s gallery, there is a “View Post” icon in the upper-right.

    See this post for the example:

    Here is what I did it:
    Modified single.php and index.php with the following:

    I moved $att = $_GET["att"]; (see first post above in this thread) from the loop and put it before the loop since I was calling this variable more than once. I now have <?php $att = $_GET["att"];?> just before the loop starts. This allows me to use the URL variable at any time to filter my post view.

    To add the buttons, I first created the buttons then added the following code just after the Title in the loop:

    <?php if ( in_category(52) ){
        echo '<a href="';
        echo the_permalink();
        if ($att=="yes")
            echo '"><img class="viewphotos" src=""></a>';
            echo '?att=yes"><img class="viewphotos" src=""></a>';

    The if (in_category(52) code looks to see if the post being compiled by the loop is in the Photo Gallery category, if it is then it looks for the $att variable in the URL. If it is yes then it means the current view is the Gallery view and the “View Post” button should be display. If $att is not yes then the view is the Post view then the “View Gallery” button is displayed and the link has ?att=yes added so the view will be filtered to the gallery when clicked on. I updated my CSS to help place the icon where I want it.

    I also added <?php if ($att=="yes") echo 'Gallery: ';?> just before the title so if the gallery is viewed, the title has “Gallery: ” added to the title.

    Skaufman, do you the ordinary code for the gallery category feature used by matt?

    No I used a modified version of the code I posted a link to in my second post above. The photo album feature is not built into WP. I suspect there will be some version of it in the future but this works well for now.

    I knew i saw that code before, thats my code, i am photoneil as you can probz see from my site. I am having problems using it within my new theme, maybe you can help?

    You’re site isn’t loading so I can’t see what is wrong. Just curious though, if it’s your code, shouldn’t you be able to figure it out? Not that I won’t try to help…

    Digg effect, damm you digg ๐Ÿ˜‰ I did try and add the code that i used in the old theme but got the “white screen of death” I think there is one small bit missing or in the wrong place, thats why im asking for your big php brain to help.

    my current index is here, maybe if you could please take the code and place it in the new one where you think it should work, that would be a great help!

    Cheers mate!!

    I might have had the same problem. Start a new thread and post a link to it here. I think it would be appropriate as it’s a different problem. I’ll post my category template there too.

    I also just added the following code to the Title in my header.php so that the title of the post when viewing the gallery filter, has “Gallery: ” added to it.

    if (is_front_page()){
        echo ' - A blog of our European Adventure';
        $att = $_GET["att"];
        if ($att=="yes") echo 'Gallery: ';
        echo ' | ';

    Hello and thanks for the useful post!

    I am trying to follow your instructions to my site but the gallery template code you paste has expired and i am stuck. Could you please re-post it?

    Thank you!

    I dont use this code on my index.php but i do use it on the archives.php, which is pretty much exactly the same, so ive posted my archives here, maybe that helps you guys? let me know ๐Ÿ˜‰

    Guys, I posted a similar approach about a month ago in case you are still looking for a like gallery tutorial

    Hi, can I add and remove images from the native images-gallery in a post?

    I can’t found how add an existent image (from just existent images in media) to the images-gallery into the editing post.

    Also I unknown how can I remove an image from gallery.

    Thank you!

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Display posts and gallery of post attachments seperately’ is closed to new replies.