PhP Call Help (3 posts)

  1. uspinnak
    Posted 6 years ago #

    I am trying to set up a 2 column system. I can get the two column just fine but the problem is they repeat the same posts. Is there a way I can have one column pull the first 6 and the second to pull the next 6? I am using this as my code:

    $my_query = new WP_Query('category_name= '. $category .'&showposts=6');
    while ($my_query->have_posts()) : $my_query->the_post();$do_not_duplicate = $post->ID;

    I am using this code in 2 separate divs to create the two columns.

  2. Wex
    Posted 6 years ago #

    Assuming that the bit of code that you posted works for the 6 posts, a quick fix would be something like this...

    <?php $my_query = new WP_Query('category_name= '. $category .'&showposts=12'); $postNumber = 0;
    while ($my_query->have_posts() && $postNumber < 6) : $my_query->the_post();$do_not_duplicate = $post->ID; ?>
    <!-- Sidebar 1 Code Here -->
    <?php $postNumber++; endwhile; ?>
    while ($my_query->have_posts() && $postNumber < 12) : $my_query->the_post();$do_not_duplicate = $post->ID; ?>
    <!-- Sidebar 2 Code Here -->
    <?php $postNumber++; endwhile; ?>
  3. uspinnak
    Posted 6 years ago #

    Thanks for that help I didn't even think of that. I modified it a little bit to try and get the call to pull one category per category page instead of information from all the most recent posts. I changed the code to this assuming that it would just pull directly from category information.

    if (have_posts()) : query_posts('posts_per_page=12');
    while (have_posts() && $postNumber < 6) : the_post();$do_not_duplicate = $post->ID; ?>

Topic Closed

This topic has been closed to new replies.

About this Topic