WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] [galley] not show if only 1 attatchment (7 posts)

  1. sputnick3k
    Member
    Posted 4 years ago #

    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

  2. sputnick3k
    Member
    Posted 4 years ago #

    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.

  3. esmi
    Forum Moderator
    Posted 4 years ago #

    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

  4. sputnick3k
    Member
    Posted 4 years ago #

    No go. Now none of the galleries show.

  5. sputnick3k
    Member
    Posted 4 years ago #

    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.

  6. sputnick3k
    Member
    Posted 4 years ago #

    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.

  7. esmi
    Forum Moderator
    Posted 4 years ago #

    Sorry about the typo first time around. Glad to hear that it's now working. :-)

Topic Closed

This topic has been closed to new replies.

About this Topic