I'm trying to make multiple gallery posts with Flexslider. The problem is that it only renders slider first time and in the second post there is no slider. Here is the code I've got so far:
Main function to retrieve attachment images from post
<?php
function deo_get_attachment( $num = 1 ){
$output = '';
if( has_post_thumbnail() && $num == 1 ):
$output = wp_get_attachment_url( get_post_thumbnail_id( get_the_ID() ) );
else:
$attachments = get_posts( array(
'post_type' => 'attachment',
'posts_per_page' => $num,
'orderby' => 'none',
'post_parent' => get_the_ID()
) );
if( $attachments && $num == 1 ):
foreach ( $attachments as $attachment ):
$output = wp_get_attachment_url( $attachment->ID );
endforeach;
elseif( $attachments && $num > 1 ):
$output = $attachments;
endif;
wp_reset_postdata();
endif;
return $output;
}
?>
Code to display slider:
<?php if ( deo_get_attachment() ) :
$attachments = deo_get_attachment(10);
?>
<div class="entry-slider">
<div class="flexslider dots-inside">
<ul class="slides clearfix">
<?php foreach( $attachments as $attachment ) : ?>
<li>
<a href="<?php echo esc_url( get_permalink() ); ?>">
<img src="<?php echo wp_get_attachment_url( $attachment->ID ); ?>" alt="">
</a>
</li>
<?php endforeach; ?>
</ul>
</div>
</div>
<?php endif; ?>