3 Loops? I need help.
-
I’m not that great in PHP, but I can get by. Right now I’ve got two separate loops going and I really need three different ones — unless you can help answer my question. My first loop, the one that is currently stand alone, brings up the most resent post from any category except #16. The beginning of the second loop bring up the most recent post in category #16. Both of these work fine but here is where things get tricky. The third call needs to be the offset by the most recent post and not include anything from category #16. So in the current state I have it offsetting 2 posts but if I were to post something to category #16 before anywhere else this system would be off. I tried three separate loops and the problem is that query_posts doesn’t allow for the offsetting of posts and while get_posts does, it doesn’t allow for excluding a category and I can’t seem to get the two to work hand in hand.
<div id="story">
<?php query_posts('showposts=1&cat=-16'); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div id="recient">
<div id="post-<?php the_ID(); ?>">
<h1>" title="Read <?php the_title(); ?>"><?php the_title(); ?></h1>
<h4>Posted <?php if (function_exists('time_since')) { echo time_since(abs(strtotime($post->post_date_gmt . " GMT")), time()) . " Ago"; } else { the_time('F jS, Y'); } ?> in <?php the_category(', ') ?> | <?php edit_post_link('Edit', '', ' | '); ?> <?php comments_popup_link('No Comments', '1 Comment', '% Comments'); ?></h4>
<?php the_content('', true, ''); ?>
<h3>Continue Reading /#more-<?php the_ID(); ?>" title="Continue Reading <?php the_title(); ?>">"<?php the_title(); ?>"</h3>
</div>
</div>
<?php endwhile; else: endif; ?>
<?php query_posts('showposts=1&cat=16'); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div id="feature">
<div id="post-<?php the_ID(); ?>">
<h2><?php the_title(); ?></h2>
<?php the_content(); ?>
<?php edit_post_link('Edit', '', ''); ?>
</div>
</div>
<?php endwhile; ?>
</div>
<div id="headlines">
<?php $posts = get_posts('numberposts=3&offset=2'); foreach($posts as $post) : setup_postdata($post); ?>
<h3>"><?php the_title(); ?></h3>
<h4><?php the_time('F jS, Y'); ?> | "><?php comments_number('No Comments','One Comment','% Comments'); ?></h4>
<?php the_excerpt(); ?>
<?php endforeach; ?>
</div>
<?php else: endif; ?>
- The topic ‘3 Loops? I need help.’ is closed to new replies.