Support » Fixing WordPress » Add HTML element after every certain post

  • Resolved bodjiang

    (@bodjiang)


    Hi all,
    I was Googling this all day, but no solution, (or I don’t see the solutions with my PHP knowledge), I was hope I can get help from here, where I often had.

    straight to the point, I had posts in “project-gallery” category displayed as gallery posts, more like this one, I wish to add a </hr> Tag after every new row, in my case after ervery fifth post. I think I need work on something on $counter, but I am going no where with my lack skill in php, can anyone help?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Something like this should work:

    <?php $c = 0; if (have_posts()) : while (have_posts()) : the_post(); $c++;?>
    [ usual Loop stuff for post display ]
    
    <?php if( $c == 5 ) :?>
    <hr />
    <?php $c = 0;
    endif;?>
    
    <?php endwhile; ?>
    <?php endif; ?>

    THANK YOU SO MUCH!!!
    You are the legend~!!!
    I manage to modify your code to make mine works, I change $c == 5 to 6 in order for it go after 5th post.
    Thanks again~!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Add HTML element after every certain post’ is closed to new replies.