Tag: Wordpress code

How to run two columns with different categories using a second WordPress Loop

Regular readers can ignore this post. This is for google. And in case I want to go back to running two separate columns of content on any other sites. I’ve decided to fold my curiosities category back into the regular run of the mill posts.

Pulling a category out of the main loop is pretty easy. It just takes a query posts loop with a nice and easy “exclude” command, excluding categories by their numerical ID (which you find by going to your categories page and clicking on the category and looking at the number in the URL).

Here’s the code for the loop for the main column.

<?php if (is_home()){$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts("cat=-655,-4811&paged=$paged");}?>
<?php if (is_page()) {$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts("cat=-655,-4811&paged=$paged");}?>

The loop for the sidebar looks a little something like this. It should produce results that give you a different output based on the page you’re looking at (so you won’t get the same ten sidebar posts on every page).

<?php if (is_home()){$paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $myPosts = new WP_Query();
$myPosts->query('showposts=10&cat=11'.'&paged='.$paged);} ?>
<?php if (is_page()){$paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $myPosts = new WP_Query();
$myPosts->query('showposts=10&cat=11'.'&paged='.$paged);} ?>
<?php while ($myPosts->have_posts()) : $myPosts->the_post(); ?>

<div>
<h2><a href=”<?php the_permalink();?>” title=”<?php the_title();?>”><?php the_title(); ?></a></h2>
<div>
<em>Posted by</em> <?php the_author_posts_link(); ?> </div>

<?php the_content();?>