【发布时间】:2011-02-25 01:24:08
【问题描述】:
我正在尝试在我目前正在开发的主题中使用 jQuery Cycle 插件。我有 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,希望有人能帮助我。
附注我知道如何从 img 的属性(例如 'alt')中获取标题,但我不想那样做,我想从 div 的内容中获取标题。
问候
-XO
【问题讨论】:
标签: wordpress jquery-cycle caption