我正在尝试使用Flexslider制作多个图库帖子。问题是,它只在第一次渲染滑块,而在第二次发布时没有滑块。以下是我目前掌握的代码:
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; ?>