0

Hi I got a problem with my secondary loop in my template page.php. I'm trying to display some testimonials, the code that retrieve those testimonials works perfectly fine in my index.php but I won't retrieve any testimonial if I make the call from my template page here is my code: slideshow.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>

And here is my code of my template page:

<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>

If I move the include before the main loop is executed it works, I will apreciate your help.

  • 1
    why is 'p' => $id in your query arguments? where do you set $id? – Milo Jan 9 '15 at 3:58
  • Thank you that was the problem I'm a little embarrased right now. I apreciate a lot your help. :) – lazaroReyes Jan 9 '15 at 19:07
0
'p' => $id

why you this? and if you create show all pages on your testimonial or slider show whatever

is_page(); use condition on footer, header, index and YOUR-TEMPLATES
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.