Php 如何在循环中使用滑块
我需要一个滑块内的循环工作,我使用下面的代码Php 如何在循环中使用滑块,php,wordpress,wordpress-theming,Php,Wordpress,Wordpress Theming,我需要一个滑块内的循环工作,我使用下面的代码 while ( have_posts() ) : the_post(); ?> <div id="content"> <?php $attachments = get_children( array( 'post_parent' => $post->ID, 'post_type' => 'attachment', 'order' => '', 'post_m
while ( have_posts() ) : the_post(); ?>
<div id="content">
<?php
$attachments = get_children( array(
'post_parent' => $post->ID,
'post_type' => 'attachment',
'order' => '',
'post_mime_type' => 'image')
);
echo "aaaaa".count($attachments);
?>
<?php if(count($attachments)!=0){ ?>
<div id="portfolio-gallery">
<ul id="slideshow_detail">
<?php
foreach ( $attachments as $att_id => $attachment ) {
$getimage = wp_get_attachment_image_src($att_id, 'room-gallery', true);
$roomimage = $getimage[0];
echo '<li>
<h3></h3>
<span>'.$roomimage.'</span>
<p></p>
<img src="'.$roomimage.'" alt="" class="thumb-slide" />
</li>';
}
?>
</ul>
<div id="wrapper1">
<div id="fullsize">
<div id="imgprev" class="imgnav" title="Previous Image"></div>
<div id="imglink"></div>
<div id="imgnext" class="imgnav" title="Next Image"></div>
<div id="image"></div>
<div id="information">
<h3></h3>
<p></p>
</div>
</div>
<div id="thumbnails">
<div id="slideleft" title="Slide Left"></div>
<div id="slidearea">
<div id="slider-room"></div>
</div>
<div id="slideright" title="Slide Right"></div>
</div>
</div>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
<!--
$('slideshow_detail').style.display='none';
$('wrapper1').style.display='block';
var slideshow_detail=new TINY.slideshow_detail("slideshow_detail");
window.onload=function(){
slideshow_detail.auto=true;
slideshow_detail.speed=5;
slideshow_detail.link="linkhover";
slideshow_detail.info="information";
slideshow_detail.thumbs="slider-room";
slideshow_detail.left="slideleft";
slideshow_detail.right="slideright";
slideshow_detail.scrollSpeed=4;
slideshow_detail.spacing=25;
slideshow_detail.active="#fff";
slideshow_detail.init("slideshow_detail","image","imgprev","imgnext","imglink");
}
//-->
</script>
</div>
<?php endwhile;?>
while(have_posts()):the_post();?>
通过使用此代码,滑块仅工作一次;我需要一个在循环下工作的滑块。
ie我必须添加多篇文章,每篇文章都有多个图像。我必须显示每篇文章的详细信息,并使用滑块显示每篇文章的图像。我觉得可能是从顶部开始的while循环出现了问题。为什么不使用if语句呢。我不熟悉你的while语法。我只见过以下情况:
<?php while( someCondition() ): ?>
//statements in here
<?php endwhile; ?>
//这里的声明
或者尝试使用if语句:
<?php if ( have_posts() ): ?>
//all slider code here
<?php } else { ?>
//give a 'there are no posts' message
<?php endif; ?>
//所有滑块代码都在这里
//发出“没有帖子”的消息
你正在运行什么wordpress插件?如果不知道这一点,解决这个问题就有点困难。在每个while循环中都包含JS。因此,如果它起作用,它会被注册多次。将JS移出循环。通过使用上面的代码,滑块仅适用于一篇文章。在剩余的文章中,图像将逐个显示