• I’ve inserted a .divider class in my stylesheet and I’m currently using this to insert a divider in between posts.

    It looks a bit ugly, however, when this divider appears at the very last post on the page. Is there a way I can control it so that this only appears in between two separate posts?

Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter ollee

    (@ollee)

    still haven’t been able to work out a way around this–anyone got any ideas?

    Let’s have a link then we can tell what you need.

    Are you adding the class to the posts themselves?

    I think the basic idea would be that you set up a conditional for adding the class. First count the number of posts that are going to be displayed, and then start a counter to keep track of how many times you add the class to a post. When you get to the last one, don’t add it.

    There are a bunch of ways to do this, so it depends on how you want to write it. If it’s not something you can come up with on your own, I can probably give you an example.

    might work the same way as adding adsense between posts, but just change the adsence to the divider maybe???

    Thread Starter ollee

    (@ollee)

    dansinch–no, I’m not adding the class to the posts; it’s in the template. I really want everything to be as automated as possible.

    razorrich–this sounds interesting. Is there a way of adding adsense between posts but not at the last one?

    What about using a different style for your last post? Let’s imagine that you have this code currently:

    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post; ?>
    <div class="post">
    my post content
    <div class="divider">&nbsp;</div>
    </div>
    <?php endwhile; ?>

    and that you limit your post numbers per page to 5. Considering this you could set-up your code like this instead:

    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post; ?>
    <?php $postclass = ($post == $posts[5]) ? 'entry-5' : 'entry'; ?>
    <div class="<?php echo $postclass; ?>">
    my post content
    <div class="divider">&nbsp;</div>
    </div>
    <?php endwhile; ?>

    The results should be that posts 1 thru 4 will use “entry” as their class, while post 5 would use “entry-5”. Then yor stylesheet could use something like this:

    .entry-5 .divider { display:none; }

    I haven’t actually tried this myself, however a post I was reading here is where the thought originated from.

    Hope this helps.

    Thread Starter ollee

    (@ollee)

    Hi cwoodside–I think that’s EXACTLY what I’m looking for! When I try this with my code, however, it seems like I’m somehow failing to close the loop (and my whole page gets filled with divider images for an eternity until I force quit it….)

    Would you ever be able to show me where I need to make these changes?

    My code is included below:

    <?php get_header(); ?>
    <div id="main"><!-- Main Start -->
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <div id="date"><?php the_time('F jS, Y') ?></div>
    <a href="<?php the_permalink() ?>" rel="bookmark"><h2><?php the_title(); ?></h2></a>
    <br>
    		<?php the_content(__('(more...)')); ?>
    <!-- E N D O F P O S T I M A G E -->
    <div class="divider">&nbsp;</div>
    <!-- E N D O F P O S T I M A G E -->
    <?php endwhile; else: ?>
    <?php endif; ?>
    </div> <!-- Main End -->
    
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>
Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘insert divider only between posts, not at the last post on a page’ is closed to new replies.