PSD to HTML conversion PSD to HTML conversion PSD2HTML.com with over 300 professionals takes the designs to HTML and beyond

Code Snippet

Home » Code Snippets » WordPress » Display Post Divider In Between Posts

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.

Subscribe to The Thread

  1. This piece of code is excellent and saved my day, thanks!

  2. 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.

  3. 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!

  4. Could you use this to insert adverts or adsense – how?
    many thanks

  5. What if you have excluded posts. Then the divider will show up even when it’s blank. Help?

  6. James Humphrey

    Thank You!!!

  7. 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.

Speak, my friend

At this moment, you have an awesome opportunity* to be the person your mother always wanted you to be: kind, helpful, and smart. Do that, and we'll give you a big ol' gold star for the day (literally).

Posting tips:
  • You can use basic HTML
  • When posting code, please turn all
    < characters into &lt;
  • If the code is multi-line, use
    <pre><code></code></pre>
Thank you,
~ The Management ~