I have been killing myself trying to figure this out on my own. And I for the life of me cannot figure out what is causing my issues.
I created a template for the testimonials page and used custom post types to fill the content. Everything looks great until I add the side bar then it creates a big gap the length of the sidebar between the first testimonial and the 2nd. And then they start formatting and showing up with the correct amount of space between each one.
I can get it to look fine and correct in HTML however once I bring it into wordpress it doesn't want to format correctly. Any ideas as to what could cause this? Thank you all in advance!
Screenshots: 1st one is html page that is "working" 2nd is what the wordpress page looks like with the gap.
get_header();
?>
<?php $loop = new WP_Query ( array ( 'post_type' => 'testimonials', 'orderby' => 'post_id', 'order' => 'ASC') ); ?>
<?php while ( $loop->have_posts() ) : $loop->the_post() ?>
<section>
<div class="container">
<div class="row">
<div class="col-12 col-md-8">
<!-- Testimony -->
<div class="row testimonials">
<div class="col-10">
<h5>
<?php the_content(); ?>
<cite>— <?php the_title();?></cite>
</h5>
</div>
</div>
</div>
<div class="col-md-4">
<?php get_sidebar(); ?>
</div> <!-- col -->
</div> <!-- row-->
</div> <!-- container -->
</section>
<?php endwhile;wp_reset_query(); ?>
<?php get_footer();
I have been killing myself trying to figure this out on my own. And I for the life of me cannot figure out what is causing my issues.
I created a template for the testimonials page and used custom post types to fill the content. Everything looks great until I add the side bar then it creates a big gap the length of the sidebar between the first testimonial and the 2nd. And then they start formatting and showing up with the correct amount of space between each one.
I can get it to look fine and correct in HTML however once I bring it into wordpress it doesn't want to format correctly. Any ideas as to what could cause this? Thank you all in advance!
Screenshots: 1st one is html page that is "working" 2nd is what the wordpress page looks like with the gap.
get_header();
?>
<?php $loop = new WP_Query ( array ( 'post_type' => 'testimonials', 'orderby' => 'post_id', 'order' => 'ASC') ); ?>
<?php while ( $loop->have_posts() ) : $loop->the_post() ?>
<section>
<div class="container">
<div class="row">
<div class="col-12 col-md-8">
<!-- Testimony -->
<div class="row testimonials">
<div class="col-10">
<h5>
<?php the_content(); ?>
<cite>— <?php the_title();?></cite>
</h5>
</div>
</div>
</div>
<div class="col-md-4">
<?php get_sidebar(); ?>
</div> <!-- col -->
</div> <!-- row-->
</div> <!-- container -->
</section>
<?php endwhile;wp_reset_query(); ?>
<?php get_footer();
I'd guess that the get_sidebar()
inside the loop is causing the problem. It should be outside the loop.
The way it is now, one post is displayed, then you call the get_sidebar()
code, which displays the sidebar stuff, then the loop continues with the next post.
Move the get_sidebar()
outside the loop.
So this is the code that I changed it to that got it working like how I wanted :) big thanks to Rick!
get_header();
?>
<div class="container">
<div class="row">
<main class="col-md-8">
<?php $loop = new WP_Query ( array ( 'post_type' => 'testimonials', 'orderby' => 'post_id', 'order' => 'ASC') ); ?>
<?php while ( $loop->have_posts() ) : $loop->the_post() ?>
<div class="testimonials">
<h5>
<?php the_content(); ?>
<cite>— <?php the_title();?></cite>
</h5>
</div>
<?php endwhile;wp_reset_query(); ?>
</main>
<!-- SIDEBAR
================================================== -->
<aside class="col-md-4">
<?php get_sidebar(); ?>
</aside>
</div><!-- #primary -->
</div><!-- .container -->
<?php get_footer(); ?>