OK,
So I have created a custom WP_Query that gets the post_type post
and outputs it as a styled list. It works well and outputs the styled list but then underneath it displays all the posts again but in a completely different format (unstyled).
<?php
// get all post types
$args = array (
'post_type' => 'post',
'post_status' => 'publish',
'pagination' => true,
'paged' => (get_query_var('paged') ? get_query_var('paged') : 1),
'posts_per_page' => 20,
'order' => 'ASC',
'orderby' => 'date',
); ?>
<?php $wp_query = new WP_Query($args); ?>
<?php if ($wp_query->have_posts()): ?>
<?php while($wp_query->have_posts()): $wp_query->the_post() ?>
<div class="row">
<div class="col-md-5">
<a href="<?php the_permalink() ?>" class="fancybox">
<?php the_post_thumbnail('medium'); ?>
</a>
</div>
<div class="col-md-7">
<!-- title and the excerpt -->
<h5><?php the_title() ?></h5>
<?php the_excerpt() ?>
<!-- post buttons -->
<a href="<?php the_permalink() ?>" class="btn btn-primary">View full story</a>
<?php if(get_field('comments_enable') !== false): ?>
<a href="<?php the_permalink() ?>#disqus_thread" class="btn btn-default"> Comments</a>
<?php endif; ?>
</div>
</div>
<hr style="margin: 10px 0; border-style: dotted; border-color: #333" class="row">
<?php endwhile; ?>
<!-- row -->
<div class="row">
<div class="col-xs-6">
<?php previous_posts_link('<i class="fa fa-arrow-left"></i> <span class="text">Previous page</span>'); ?>
</div>
<div class="col-xs-6 text-right">
<?php next_posts_link('<span class="text">Next page</span> <i class="fa fa-arrow-right"></i>'); ?>
</div>
</div>
<?php else: ?>
<p class="text-muted">No news right now, please check back later.</p>
<?php endif; unset($wp_query); wp_reset_postdata(); ?>
This is all in a template partial and called using the get_template_part()
method. If I assign the WP_Query to a variable other than $wp_query
it doesn't double up but I need it to be $wp_query
for the pagination links to work. I am also unsetting $wp_query
and resetting the post data at the end of the loop. Puzzled and I hope you can help!