multiple loops, if first post in loop 1 matches first post in loop 2, skip…
-
I have my index set up with two loops. The first loop shows the four latest posts from categories 3, 4, and 5. The second loop shows posts from categories 1 and 3. The problem is that every now and then, a post will show up as the first post in loop 1 which will match the first post in loop 2. In cases like these, I would like the first post in loop 1 to not show. I’ve attempted this (incorrectly) in my code below with
$first_post = $id == 1;
andif( $post->ID == $first_post ) continue;
. If anyone can help me out with this, I would really appreciate it.<?php get_header(); ?> <div id="page"> <div class="content"> <?php $first_post = $id == 1; /************************* LOOP 1 Four Posts in a Carousel **********************/ query_posts('cat=3,4,5&showposts=4'); while (have_posts()) : the_post(); if( $post->ID == $first_post ) continue; $Thumbnail = get_post_meta($post->ID, 'Thumbnail', $single = true); ?> <div id="carousel-post" style="border-right: 1px solid #dddddd; display:inline; float:left; height:170px; margin:0 0 20px 0; padding:5px; width:145px;"> <center><div class="carousel-thumb"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><img class="blog-avatar" width="100" height="100" src="<?php echo get_post_meta($post->ID, "Thumbnail", true);?>" /></a></div></center> <h2 style="font-size:1.3em; margin:5px 0 0 0"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php if (strlen($post->post_title) > 60) { echo substr(the_title($before = '', $after = '', FALSE), 0, 60) . '...'; } else { the_title(); } ?></a></h2> </div> <?php endwhile; /************************* LOOP 1 Ends **********************/ /************************* LOOP 2 Main Page Posts **********************/ query_posts('cat=1,3'); while (have_posts()) : the_post(); update_post_caches($posts); $Thumbnail = get_post_meta($post->ID, 'Thumbnail', $single = true); ?> <div class="post" id="post-<?php the_ID(); ?>"> <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2> <div class="postmetadata" style="border-bottom:1px dotted #888; padding-bottom:10px; padding-top:10px; line-height:18px;"> <!-- post author --> by <?php the_author() ?> <!-- the date and time --> on <?php the_time(get_option('date_format')) ?> <!-- post category under <?php the_category(', ') ?>.--> <div id="home-ratings" style="float:right;"><?php if(function_exists('the_ratings')) { the_ratings(); } ?></div> </div> <div class="entry"> <?php if($Thumbnail !== '') { ?> <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><img src="<?php echo $Thumbnail;?>" width="150" style="border:2px solid #dfdfdf; float:right; margin-left:10px;" /></a> <?php } ?> <?php if (function_exists('tweetmeme')) echo tweetmeme(); ?> <?php add_filter('excerpt_length', create_function('','return "75";')); ?> <?php the_excerpt(); ?> </div> <div class="postmetadata"> <div style="text-align:right;" class="read-more"><a href="<?php the_permalink(); ?>" title="Read the rest of <?php the_title(); ?>" class="more-link">Read more »</a></div> <?php if( function_exists('the_tags') ) the_tags(__('Tags: '), ', ', '<br />'); ?> <?php edit_post_link('Edit', '', ' | '); ?> <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></div> </div> <?php endwhile; /************************* LOOP 2 Ends **********************/ ?> <div class="navigation"> <div style="text-align:left"><?php next_posts_link('« Older Entries') ?></div> <div style="text-align:right"><?php previous_posts_link('Newer Entries »') ?></div> </div> </div> <?php get_sidebar(); ?> </div> <?php get_footer(); ?>
Viewing 10 replies - 1 through 10 (of 10 total)
Viewing 10 replies - 1 through 10 (of 10 total)
- The topic ‘multiple loops, if first post in loop 1 matches first post in loop 2, skip…’ is closed to new replies.