Right before the closing of the The Loop, insert this code:
<?php
if (($wp_query->current_post + 1) < ($wp_query->post_count)) {
echo '<div class="post-item-divider">Post Divider</div>';
}
?>
This will create a <div>
you can style as a post divider. The cool part being, it only gets inserted between two posts, skipping the last one. Thanks to Craig Maclean.
This piece of code is excellent and saved my day, thanks!
What’s great is you can utilize this technique to output just about anything you want before and after your post data, including objects with specific id’s for manipulation with javascript.
Gotta love the loop.
Wow, this code is awesome! I’ve been looking for ways to separate posts easily for a while, this is definitely something I’ll set up!
Could you use this to insert adverts or adsense – how?
many thanks
What if you have excluded posts. Then the divider will show up even when it’s blank. Help?
Thank You!!!
Thanks for this snippet.
So I imagine that the CSS looks like:
.div.postdivider { background image: url(whatever)
}
??
What other coords should be in place for this to work? I’m a fairly new designer so please forgive me. Thanks.
nice snippet ;) i did something similar recently, i had a design that i needed to add a last class to every 4th post.
seeems this code is for experts only, it assumes a lot….
would you please clear what do you mean by….
“Right before the closing of the The Loop, insert this code”?
Prakash,
Check out http://codex.wordpress.org/The_Loop for an explanation of The Loop. The short story is you paste the code above before this bit of code:
Thanks, this worked great! Now I’m off to create my first web app (had to wait until the kids started school full time).
Did it! Thak you! Now how can style it? http://blogdenuria.com
I think this technique is obsolete in this days, its better to use pure CSS technique something like
Awesome! THX PayteR.
What about on the search results with different post classes? Something like adding a top or bottom border to every class, and removing the last child?
Great snippet! Thank you!