Why isn’t this sorting by category?
-
I have the following code in index.php to sort my posts by category into two divs floated left and right
index.php:
<?php get_header (); ?> <div id="box"> <div id="left"> <?php $my_query = new WP_Query ( 'category_name=tony&showposts=3' ); while ( $my_query->have_posts () ) : $my_query->the_post (); $do_not_duplicate = $post->ID; endwhile; /*end tony post while*/ if (have_posts ()) : while ( have_posts () ) : the_post (); ?> <div class="post"> <h3> <a href="<?php the_permalink ();?>"><?php the_title ();?></a> </h3> <div class="entry"> <?php the_content ();?> </div><!-- end entry div --> </div><!-- end post div --> <?php endwhile;/*end tony while have posts*/ endif; /*end of tony have posts*/ ?> </div><!-- End Left Div --> <div id="right"> <?php $my_query = new WP_Query ( 'category_name=hippie&showposts=3' ); while ( $my_query->have_posts () ) : $my_query->the_post (); $do_not_duplicate = $post->ID; endwhile;/*end hippie post while*/ if (have_posts ()) : while ( have_posts () ) : the_post (); ?> <div class="post"> <h3> <a href="<?php the_permalink ();?>"><?php the_title ();?></a> </h3> <div class="entry"> <?php the_content ();?> </div><!-- end entry div --> </div><!-- end post div --> <?php endwhile;/*end hippie while have posts*/ endif; /*end of hippie have posts*/ ?> </div><!-- End Right Div --> </div><!-- end box div --> <?php get_sidebar (); get_footer (); ?>it outputs all posts to both divs instead of dividing them by category. Can anyone spot the problem? Thanks a lot
The topic ‘Why isn’t this sorting by category?’ is closed to new replies.