0

This probably sounds unusual (it does to me) but in a wordpress image slideshow (using get attachments), if an image doesn't have a caption, I want to keep the previous caption on display until the next populated caption comes around.

Is this possible?:/

Thanks in advance for any help!

4

1 回答 1

0

好吧,它现在已经排序,并且很抱歉之前没有显示代码,这是一个对我有用的解决方案;

<?php endif; ?>
    <?php if (have_posts()) : while (have_posts()) : the_post();
    $attachments = attachments_get_attachments();
    $total_attachments = count($attachments);
        if( $total_attachments > 0 ) :
        for ($i=0; $i < $total_attachments; $i++) : ?>
            <div><img src="<?php echo $attachments[$i]['location']; ?>" alt="<?php echo $attachments[$i]['caption']; ?>" title="<?php echo $attachments[$i]['title']; ?>">
            <?php if($attachments[$i]['caption']==""){
                 $new_caption=$attachments[$i-1]['caption'];    
            }else{
                 $new_caption=$attachments[$i]['caption'];  
            }
            ?>
            <h2 id="tagline" title="<?php echo $attachments[$i]['title']; ?>"><?php echo $new_caption; ?></h2>
            </div>
            <?php endfor; ?>
            <?php endif; ?>
    <?php endwhile; else: ?>
于 2012-11-19T23:19:20.057 回答