我正在尝试使用Wordpress循环(特定类别)来提取特色图像,链接和摘录,并填充幻灯片JS中的Ultimate Fade。代码输出正确的格式,语法,并正确显示两个帖子的链接。但是,此代码不会循环显示特色图像。它似乎在同一图像之间褪色两次。
此特定类别目前有两个帖子,两个图片都设为特色。每篇文章也都有摘录。
所有文档(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上进行了彻底搜索,但没有找到任何可以尝试的内容。我相信也许我不知道什么是错误的,知道还有什么可以搜索。我相信有一个相当简单的解决方案,我根本没有经验知道出了什么问题。
非常感谢你的帮助和知识!
答案 0 :(得分:0)
不完全确定为什么会这样 - 但我解决了这个问题。我没有在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
}
}
?>
除了仍然没有循环,但至少缩略图。