Domanda

I'm trying to create a div containing the featured image's caption appear in the middle of the slider.

Why is the caption looping?

link: http://natashamcdiarmid.com/clients/JLP/wp/

how it should look: http://natashamcdiarmid.com/clients/JLP/

<div class="slider">
    <?php query_posts( 'post_type=page' ); ?>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
        <?php the_post_thumbnail('slider'); ?>
        <div class="caption-wrap"><?php the_post_thumbnail_caption(); ?></div>
    <?php endwhile; else: ?>
    <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
    <?php endif; ?>
</div>
È stato utile?

Soluzione

I never see this function the_post_thumbnail_caption();, so change it by get_post( get_post_thumbnail_id() )->post_excerpt

<div class="slider">
    <?php query_posts( 'post_type=page' ); ?>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
        <?php the_post_thumbnail('slider'); ?>
        <div class="caption-wrap"><?php echo get_post( get_post_thumbnail_id() )->post_excerpt ?></div>
    <?php endwhile; else: ?>
    <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
    <?php endif; ?>
</div>

Altri suggerimenti

Ok I figured it out:

<div class="slider">
    <?php query_posts( 'post_type=page&page_id=48' ); ?>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
        <?php the_post_thumbnail('slider');
        echo '<div class="caption-wrap">' . get_post(get_post_thumbnail_id())->post_excerpt . '</div>'
        ; ?>
    <?php endwhile; else: ?>
    <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
    <?php endif; ?>
</div>
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top