Code Snippet
Display Post Divider In Between Posts
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.
DigWP
A book and blog co-authored by Jeff Starr and myself about the World's most popular publishing platform.
Quotes on Design
Design, like Art, can be an elusive word to define and an awfully fun thing to have opinions about.
HTML-Ipsum
One-click copy to clipboard access to Lorem Ipsum text that comes wrapped in a variety of HTML.
Bookshelf
Hey Chris, what books do you recommend? These, young fertile mind, these.