Skip to content

Instantly share code, notes, and snippets.

@thefrosty
Created September 19, 2010 00:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thefrosty/586232 to your computer and use it in GitHub Desktop.
Save thefrosty/586232 to your computer and use it in GitHub Desktop.
If there is more than one attachment, add a second shortcode parameter:
<?php
if ( in_category( 'photo' ) ) {
do_shortcode( '[gallery numberposts="1" columns="1" link="attachment"]' );
//http://wordpress.org/support/topic/if-postpage-has-more-than-one-attachment
$args = array(
'post_type' => 'attachment',
'numberposts' => -1,
'post_status' => null,
'post_parent' => $post->ID,
'post_mime_type' => 'image'
);
$attachments = get_posts($args);
if ($attachments) {
$c = 0;
foreach ($attachments as $attachment) {
if ( wp_attachment_is_image( $attachment->ID ) ) $c++;
}
if ( $c > 1 ) {
do_shortcode( '[gallery numberposts="9" columns="3" offset="1" size="thumbnail"]' );
}
}
} else {
the_content('<p class="serif">Read the rest of this entry &raquo;</p>');
} ?>
@thefrosty
Copy link
Author

Forgot the echo's before the "do_shortcode".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment