1

在修复我的这个小推荐箱时,我将不胜感激。现在,我不知道问题出在 PHP、CSS 还是我的标记上,因为虽然帖子似乎褪色了,但它们都同时出现,第一个褪色只是继续显示第三个帖子。

这是脚本:

    <script language="javascript"> 
jQuery(document).ready(function(){
    jQuery('#testimonials .slide');
    setInterval(function(){
        jQuery('#testimonials .slide').filter(':visible').fadeOut(1000,function(){
            if(jQuery(this).next('.slide').size()){
                jQuery(this).next().fadeIn(1000);
            }
            else{
                jQuery('#testimonials .slide').eq(0).fadeIn(1000);
            }
        });
    },1500);    
}); 
</script>

PHP/HTML:

<?php 
  $loop = new WP_Query(array('post_type' => 'qcamp', 'posts_per_page' => 5)); 
  if ($loop->have_posts()) { ?>
<div id="camps-quote">

<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>

    <div id="testimonials">
        <div class="slide">
            <div class="testimonial-quote">
            <?php the_content(); ?>
            </div>
        </div>

    </div>

<?php endwhile; ?>  

</div>
<?php } ?>

最后是 CSS:

#camps-quote {
    margin-top:50px;
    box-shadow: 7px 7px 7px #C0C0C0; 
    background-color: #7D9EC0; 
    height: 120px; 
    font-size: 16px;
    padding:7px;
    font-family: Arial;
    width:500px;
    margin-left:200px;
    overflow:hidden;
}

#testimonials{

}

#testimonials .slide {color: #fff;}

#testimonials .testimonial-quote {
    padding: 3px 0 0 65px; 
    line-height: 1.5em; 
    font-family:Helvetica, Arial, sans-serif !important; 
    font-size: 16px; 
    font-weight: normal; 
    font-style: italic; 
    margin: 10px 0 20px 0;
}

这是我正在测试它的网站。

4

2 回答 2

2

php / markup / javascript 中的一个问题#testimonials是在循环内部。它应该不在循环中,因为现在您的.slide元素没有兄弟姐妹并next()获得下一个兄弟姐妹(并且每个页面只能有一个唯一 ID;现在您拥有的#testimonials元素与您的推荐一样多):

<div id="testimonials">
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>

        <div class="slide">
            <div class="testimonial-quote">
            <?php the_content(); ?>
            </div>
        </div>

<?php endwhile; ?>  
</div>
于 2013-03-06T01:37:02.663 回答
1

您需要做两件事 - (1)<div id="testimonials">从循环中删除。并且(2)将除第一个之外的所有内容设置<div class="slide">style="display:none"页面加载。您可以通过设置一个基本计数器来做到这一点(即。$i=0; $i++;

<?php 
  $loop = new WP_Query(array('post_type' => 'qcamp', 'posts_per_page' => 5)); 
  if ($loop->have_posts()) { ?>
<div id="camps-quote">
<div id="testimonials">
<?php $i=0; // set up a basic counter counter ?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>

        <div class="slide" <?php if ($i > 0) echo 'style="display:none"'; ?> >
            <div class="testimonial-quote">
            <?php the_content(); ?>
            </div>
        </div>
<?php $i++; // increase the counter ?>
<?php endwhile; ?>  

</div>
</div>
<?php } ?>

查看 jsfiddle - http://jsfiddle.net/CEqKu/

于 2013-03-06T01:59:08.087 回答