Support » Fixing WordPress » [galley] not show if only 1 attatchment

  • Resolved sputnick3k

    (@sputnick3k)


    I am building an a Fine Art Photoblog (http://www.nicholasiversongallery.com/) and I would like to hard code the gallery code into the template using:

    <?php echo do_shortcode(‘[gallery option1="value1"]‘); ?>

    The issue is that not all posts will have a gallery but all posts will have a post_thumbnail using the built-in WordPress thumb. Since the thumbnail is an attachment as well, it will create a Post_thumbnail AND an a gallery with just one image in it. What i would like to do is create a conditional element for the galley that if there is only 1 attachment, wordpress wont generate a gallery and if there is more then one, it will create a gallery.

    Is there a way to do this or is there a better way. The site above I just manually inserted the galleries. I would like this to be an automated process.

    Thanks in advance

Viewing 6 replies - 1 through 6 (of 6 total)
  • Ok, with a plugin I have, I set the post thumbnail and then detach the image from the post and so far the post thumb will still use that photo. So a work around has been found. BUT it is an added step I would like to not do if there is a alternative I can use.

    esmi

    (@esmi)

    Forum Moderator

    How about:

    <?php $images =& get_children( 'post_type=attachment&post_mime_type=image' );
    if( count(images) < 1 ) echo do_shortcode('[gallery option1="value1"]'); ?>

    http://codex.wordpress.org/Function_Reference/get_children

    No go. Now none of the galleries show.

    I think you need count(image) to be count($image). At least that way the galleries are showing up but its not filtering the ones that only have 1 image. I left the code in so you can take a look. (http://www.nicholasiversongallery.com/). Plus i tried changing the “<” to “>” and that doesn’t work either.

    FIXED!

    <?php $images =& get_children( ‘post_parent=’.$id.’&post_type=attachment&post_mime_type=image’ );
    if( count($images) > 1 ) echo do_shortcode(‘[gallery option1="value1" columns="4"]‘); ?>

    I had to call the Post ID. THANK YOU Esmi! You are my hero.

    esmi

    (@esmi)

    Forum Moderator

    Sorry about the typo first time around. Glad to hear that it’s now working. 🙂

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘[galley] not show if only 1 attatchment’ is closed to new replies.