Code Stuff


One of my sites has two WordPress loops on the front page. At the top of the page is a "featured" section which displays the one most recent post from a certain category. A second loop is below that which displays all the posts in every category, except the one post already shown in the featured spot. (We use the code from this page of the WordPress site, under "Multiple Loops in Action".) When a new post in the featured category goes up, the older one moves down to the loop below.

Sometimes this featured post is full of really great content. Other times it is basically just a "here is what's new on the site this week" type of post. When it is just an update post we really did not want it eventually moving down into the second loop. After a week or two or three, it would be obsolete information but would still be taking up a post on our front page. Now you could split these in to different categories, then tell the second loop to ignore that category. But for our site it really needs to be one category and splitting it is not a good option. So we added an option to selectively choose which featured posts slide down to the page and which just disappear to the archives.

This is a very easy fix. On the editing page in WordPress, one of the custom fields we use is called "post-lite". The writer enters "yes" here if he wants the blog post to disappear from the front page after a new post replaces it. If the field is left empty, the post moves to the loop below after being replaced. The featured category loop remains the same. The second loop looks like this:


<?php if (have_posts()) : while (have_posts()) : the_post(); 
	if( $post->ID == $do_not_duplicate ) continue;
	$post_lite = get_post_meta($post->ID, 'post-lite', true); if ($post_lite) continue;
	update_post_caches($posts); ?>

<!-- your post code -->

<?php endwhile; endif; ?>

This is the basic WordPress loop with a few additions to allow multiple loops on one page. The code you'll need for this edit is on line 3. This code looks to see if there is anything entered in the custom field of the post called "post-lite". If there is, it skips the post and moves to the next. (Note above where I said writers would enter "yes" if the want to activate the "post-lite". Technically if they enter anything in that custom field it activates the feature.)