I'm stuck at something that should be a really simple task.. But I don't know how to do it because it involves looping out the default "posts" of the global $wp_query
.
Consider this code:
<section id="blog-wrapper">
<ul id="blog-list" class="list-reset">
<?php
$args = array(
'posts_per_page' => 5,
'paged' => $paged
);
global $wp_query;
$wp_query = new WP_Query( $args );
?>
<?php if ( $wp_query->have_posts() ) : while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
<li class="clear-fix blog-post">
<h1 class="blog-post-title"><?php the_title(); ?></h1>
<article class="blog-post-content"><?php the_content(); ?></article>
<span class="blog-post-info">Posted by <span class="author">
<?php the_author(); ?></span> on <?php the_time('F j, Y'); ?></span>
<div class="blog-post-border"></div>
</li>
<?php endwhile; ?>
</ul>
<?php
if ( function_exists( 'pagination' ) ) {
pagination( $wp_query->max_num_pages );
}
?>
<?php endif; wp_reset_postdata(); ?>
</section>
Now what I need is being able to pass the $args
into the global $wp_query
and loop out as many posts that I have posted. Then I need to pass the max_num_pages
of the global $wp_query
to a pagination function which creates the pagination.
How do I do this? All my attempts has failed and I'm going completely mad. This is my best attempt so far, but the pages after the first one are just completely empty instead of containing more posts..