Wordpress和DD's幻灯片中的终极淡出:代码没有't滚动缩略图

Wordpress and DD's Ultimate Fade-in Slideshow: Code Doesn't Scroll Through Thumbnails

本文关键字:代码 略图 淡出 滚动 DD 幻灯片 Wordpress      更新时间:2023-09-26

我正在尝试使用Wordpress循环(特定类别(来提取特色图像、链接和摘录,并填充幻灯片JS中的最终淡入淡出。该代码输出正确的格式和语法,并正确显示到这两篇文章的链接。然而,此代码并没有在特色图像中循环。它似乎在同一张图片之间褪色了两次。

目前,这一特定类别中有两个帖子,都以图片为特色。每个帖子都有一段摘录。

所有文档(fadeslideshow.js和jQuery(都在标题中正确链接,在使用Safari的web检查器查看代码时(动态驱动脚本显示透明度发生了变化(,它只是在同一个图像之间切换,所以看起来什么都没发生。

下面的代码在一个单独的.php文档中,该文档在标题中被调用。

<script type="text/javascript">
<?php query_posts('cat=7'); ?> //queries posts only from featured category
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
var mygallery=new fadeSlideShow({ 
wrapperid: "fadeshow", //ID of blank DIV on page to house Slideshow
dimensions: [585, 350], //width/height of gallery in pixels. Should reflect dimensions of largest image
imagearray: [
<?php   $thumbnails = get_posts('posts_per_page=5'); //adding category=7 here breaks code
        $my_excerpt = get_the_excerpt();
        $url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); 
        $total = count($thumbnails); //this is to count the number of thumbnails in foreach loop to NOT add a comma to the last one
        $i=1;
        foreach ($thumbnails as $thumbnail) {
        if ( has_post_thumbnail($thumbnail->ID)) {
        $i++;
         echo '["'.$url.'","'.get_permalink( $thumbnail->ID ).'","","'.$my_excerpt.'"]'; //This spits out the exact correct code
         if ($i != $total) { echo', '; }//this is to count the number of thumbnails in foreach loop to NOT add a comma to the last one
 }} ?>
],
displaymode: {type:'auto', pause:3000, cycles:0, wraparound:false},
persist: false, //remember last viewed slide and recall within same session?
fadeduration: 500, //transition duration (milliseconds)
descreveal: "ondemand",
togglerid: ""
})
<?php endwhile; endif; ?> //This ends the wordpress loop
<?php wp_reset_query(); ?>
</script>

Dynamic Drive的终极渐变幻灯片信息如下:http://www.dynamicdrive.com/dynamicindex14/fadeinslideshow.htm

我的代码在这个网站上:http://johnharvey.hsjjr.net

我还尝试过使用wp_get_attachment_image_src,但没有成功。

我在谷歌、动态硬盘论坛和Wordpress Codex上进行了彻底的搜索,但没有找到其他可以尝试的东西。我相信,也许我对出了什么问题还不够了解,不知道该寻找什么。我相信有一个相当简单的解决方案,我只是没有经验知道出了什么问题。

非常感谢大家的帮助和知识!

不完全确定为什么这样做有效,但我解决了问题。我没有定义foreach循环上方的变量,而是将其向下移动到循环中:

<?php   $thumbnails = get_posts('posts_per_page=5'); //adding category=7 here breaks code
        $total = count($thumbnails); //this is to count the number of thumbnails in foreach loop to NOT add a comma to the last one
        $i=1;
        foreach ($thumbnails as $thumbnail) {
        if ( has_post_thumbnail($thumbnail->ID)) {
        $i++;

         echo '["'.wp_get_attachment_url( get_post_thumbnail_id($thumbnail->ID) ).'","'.get_permalink( $thumbnail->ID ).'","","'.get_the_excerpt($thumbnail->ID).'"]'; //This spits out the exact correct code
         if ($i != $total) { echo', '; }//this is to count the number of thumbnails in foreach loop to NOT add a comma to the last one

 }
}
?>

except仍然不会循环通过,但至少缩略图会循环通过。