0

我正在尝试在我目前正在开发的主题中使用 jQuery Cycle Plugin。我有 jQuery Cycle 在主页上显示帖子图像的幻灯片。但是,我的问题是我无法正确显示包含 the_title() 和 the_excerpt() 作为标题的 div 的内容。我正在使用以下代码:

<script>
    $(function() {
        $('#slideshow').cycle({
            fx:       'fadeZoom',
            timeout:   2000,
            after: onAfter
        });
    });
    function onAfter(curr,next,opts) {
        var caption = $('.featured-entry').text();
        $('#caption').html(caption);
    }
</script>

<div id="container">
    <div class="pics" id="slideshow">
        <?php
            $slideshow_posts = new WP_Query('cat=3&posts_per_page=5');
            while($slideshow_posts->have_posts())
                $slideshow_posts->the_post();
                $picture = get_post_meta($post->ID, 'picture', true);
                if(!empty($picture))
                {
                ?>
                    <div class="slideshow-inner">
                        <a class="featured-article" href="<?php the_permalink(); ?>"><img src="<?php echo $picture; ?>" /></a>
                        <div class="featured-entry">
                            <a class="entry-title" href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a>
                            <div class="entry-summary"><?php the_excerpt() ?></div>
                        </div>
                    </div>
                <?php
                }
            }
        ?>
    </div>
    <div id="caption"></div>
</div>

这段代码的问题是它只显示所有幻灯片的一篇文章的摘录。这意味着当图像更改时 the_excerpt 不会更改。

那么我缺少什么?这是我第一次使用 jQuery,我希望有人可以帮助我。

PS 我知道如何从 img 的属性(例如“alt”)中获取标题,但我不想那样做,我想从 div 的内容中获取标题。

问候

-XO

4

1 回答 1

1

试试这个

function onAfter(curr, next, opts) {
    var caption = $(next).find('.featured-entry').text();
    $('#caption').html(caption);
}

$('featured-entry')应该顺便说一句。从不工作——它不是一个有效的选择器。

于 2011-02-24T10:59:35.110 回答