I’m trying to put together a custom wordpress theme. At the moment I have two bits of code, one to show 5 posts per page with pagination, and another bit of code to show 3 popular posts on the sidebar. I think the two pieces of code must be affecting each other, as the sidebar is showing double the amount of popular posts as it should be.
The first bit to show the most recent 5 posts is:
<?php // Display blog posts on any page @ http://m0n.co/l
$temp = $wp_query; $wp_query= null;
$wp_query = new WP_Query(); $wp_query->query('showposts=5' . '&paged='.$paged);
while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
<h4>Posted on <?php the_date('F j, Y'); ?> | in <?php the_category( ' ' ); ?> | by <?php the_author(); ?></h4>
<?php the_post_thumbnail(); ?>
<?php the_excerpt(); ?>
<?php endwhile; ?>
<?php if ($paged > 1) { ?>
<nav id="nav-posts">
<div class="prev"><?php next_posts_link('« Previous Posts'); ?></div>
<div class="next"><?php previous_posts_link('Newer Posts »'); ?></div>
</nav>
<?php } else { ?>
<nav id="nav-posts">
<div class="prev"><?php next_posts_link('« Previous Posts'); ?></div>
</nav>
<?php } ?>
<?php wp_reset_postdata(); ?>
The second bit of code for the sidebar is:
<?php while ( have_posts() ) : the_post(); ?>
<?php $pc = new WP_Query('orderby=comment_count&ignore_sticky_posts=1&posts_per_page=3'); ?>
<?php while ($pc->have_posts()) : $pc->the_post(); ?>
<div class="popularpost">
<div class="popularpostsimg"><?php the_post_thumbnail('sidebar'); ?></div>
<div class="popularpoststext"><h3 class="sidebartext"><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h3></div>
</div>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php endwhile; ?>
PHP isn’t exactly my forte so I would really appreciate any help.