Secondary loop doesn't work

时间:2015-01-09 作者:lazaroReyes

嗨,我的模板页面中的二次循环有问题。php。我试图显示一些证明,检索这些证明的代码在我的索引中工作得非常好。php,但如果我从模板页面调用,我不会检索任何推荐信息。这里是我的代码:幻灯片。php

<div class="jumbotron bg-black">
  <div class="row">
    <div class="container experience">
      <hr>
      <h2><strong>EXPERIENCIA</strong></h2>
      <hr style="width:300px;">
      <div id="myCarousel2" style="height:250px;" class="carousel slide" data-ride="carousel">
        <!-- Indicators -->
        <ol class="carousel-indicators">
            <?php
                $query = new WP_Query(array( \'post_type\' => \'testimonial\',\'p\' => $id, \'order\' => \'ASC\', \'showposts\' => \'11\'));
                $i = 0;
                if($query->have_posts()):
                while($query->have_posts()) : $query->the_post();
                if($i == 0) { ?>
                    <li data-target="#myCarousel2" data-slide-to="<?php echo $i;?>" class="active"></li>
           <?php
                }else { ?>
                    <li data-target="#myCarousel2" data-slide-to="<?php echo $i;?>"></li>
           <?php
                }
                $i++;
                endwhile;
                else: ?>
                <p><?php _e( \'Oh God Why?\' ); ?></p>
                <?php endif;
            ?>
        </ol>
          <!-- Wrapper for slides -->
        <div class="carousel-inner" >
          <?php
            $j = 0;
            if($query->have_posts()):
            while($query->have_posts()) : $query->the_post();
            if($use_excerpt){
                 $testimonial[\'content\'] = get_the_excerpt();
            } else {
                 $testimonial[\'content\'] = get_the_content();
            }

            if($j == 0) { ?>
                <div class="item active" style="height:250px; width:800px;">
         <?php
            }else { ?>
                <div class="item" style="height:250px; width:800px;">
         <?php
            } ?>
            <div class="carousel-caption" style="width:800px;">
              <p> <?php echo $testimonial[\'content\']; ?></p>
            </div>
        </div>
        <?php
            $j++;
            endwhile;
            endif;
            wp_reset_postdata();
        ?>
        </div>

      </div>

    </div>
  </div>
</div>

这是我的模板页面代码:

<div class="jumbotron-2">
  <div class="row">
    <div class="banner">
      <img src="<?php bloginfo(\'template_url\')?>/img/banner/empresa.jpg" class="img-responsive" alt="">
    </div>
  </div>
</div>

<div class="container">
  <div class="row">
      <div class="col-lg-12">
        <div class="row">
          <div class="icon-b"><img src="<?php bloginfo(\'template_url\')?>/img/icon-b.png" class="img-responsive" alt=""></div>
           <h2 style="text-align:center;"><strong><?php the_title(); ?></strong></h2>
          <hr>
          <div class="col-lg-4 col-md-4 col-ms-4"><br><img src="<?php bloginfo(\'template_url\')?>/img/empresa.jpg" class="img-circle"  alt="Empresa PERCHISA Perforaciones en Chihuahua SA de CV"></div>
          <div class="col-lg-8 col-md-8 col-ms-8">
               <?php
                     if (have_posts()) : while (have_posts()) : the_post();
                        the_content();
                     endwhile; else: ?>
                    <h1>No se encontraron articulos</h1>
               <?php
                    endif;
              ?>
          </div>
        </div>
      </div>
  </div>
  <hr>
</div>

如果我在主循环执行之前移动include,它就会工作,我将感谢您的帮助。

1 个回复
最合适的回答,由SO网友:Irfan 整理而成

\'p\' => $id
你为什么这样?如果你创建了“在你的推荐信上显示所有页面”或“滑块显示任何内容”

is_page(); use condition on footer, header, index and YOUR-TEMPLATES

结束

相关推荐

Infinite blog loop

我不明白为什么我会收到一个无限的博客帖子。当我注释内容中的循环代码时。php,它不再循环。我正在尝试根据post格式发布项目,但到目前为止失败了。如果我需要提供更多信息,请告诉我!我很感激。所容纳之物php:<?php /** * The default template for displaying content. Used for both single and index/archive/search. * * @subpackage Foundatio